-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create example for parallel server #131
Conversation
This server sends and receives messages independently
Could you add |
Thanks for the reminder. |
Hey this is awesome! Thanks a bunch, travis was being weird but now it's fixed. Feel free to rebase on top of the latest changes. |
Hmm, any idea why my Edit: I see, you're running an old version of rustfmt. I'm gonna downgrade my local installation then. Maybe in the future you should look into https://github.com/nabijaczleweli/cargo-update. With it you can cache your rustfmt on Travis and let it auto update as needed :) |
Feel free to merge it now. I wrote this example with a game server in mind. As I am not that experienced in working with futures, I most probably made some things way more complicated that they could be. But hey, it's parallel and scalable to as many users as you like :) |
Thank you again! |
Regarding the code in this example: send_channel_in.for_each(move |(id, msg): (Id, String)| {
let connections = connections.clone();
let sink = connections.write()
.unwrap()
.remove(&id)
.expect("Tried to send to invalid client id",);
println!("Sending message '{}' to id {}", msg, id);
let f = sink.send(OwnedMessage::Text(msg))
.and_then(move |sink| {
connections.write().unwrap().insert(id, sink);
Ok(())
});
remote.spawn(move |_| f.map_err(|_| ()));
Ok(())
})
.map_err(|_| ()) Isn't it possible that the last message haven't been sent completely but the |
Good catch, I think you're right. Unfortunately I don't have time right now to fix it. Do you wanna give it a try? |
I've create the pull request #148, but since I'm a newbee to tokio and future, maybe you could check whether my fix is correct. |
This server sends and receives messages independently