Crates.io | messenger |
lib.rs | messenger |
version | 0.1.0 |
source | src |
created_at | 2018-02-27 17:21:37.541709 |
updated_at | 2018-02-27 17:21:37.541709 |
description | two way messenger |
homepage | https://gitlab.com/nathanfaucett/rs-messenger |
repository | https://gitlab.com/nathanfaucett/rs-messenger.git |
max_upload_size | |
id | 53066 |
size | 16,022 |
two way messenger
extern crate messenger;
extern crate tokio;
use messenger::unbounded_channel;
use tokio::executor::current_thread;
fn main() {
let (ping, pong, future) = unbounded_channel();
let _ = ping.on("message", |m| {
println!("Ping received {:?}", m);
Some("Pong".to_owned())
});
let p = pong.clone();
let _ = pong.send("message", "Pong".to_owned(), move |data| {
println!("Pong callback {:?}", data);
p.close();
});
current_thread::run(move |_| {
let _ = current_thread::spawn(future);
});
}