Skip to content

Instantly share code, notes, and snippets.

@tobz
Forked from rust-play/playground.rs
Last active September 18, 2018 19:26
Show Gist options
  • Save tobz/0d6d5d4b2672d96910857e5b717a4854 to your computer and use it in GitHub Desktop.
Save tobz/0d6d5d4b2672d96910857e5b717a4854 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
extern crate tokio; // 0.1.8;
extern crate futures; // 0.1.24;
use futures::sync::mpsc;
use futures::{task, Async, Future, Sink, Stream};
pub fn invoke_bpm_battle_warm_up( // this method is called from the poll parent method
receiver: &mut Option<mpsc::Receiver<bool>>,
msg: BattleWarmUp,
addr: Addr<Bpm>,
) {
let _ = receiver.get_or_insert_with(|| {
let (tx, rx) = mpsc::channel::<bool>(1);
let future = addr
.send(msg)
.map_err(Into::into)
.and_then(|r| r)
.map_err(|_| format_err!("mpsc send error"))
.and_then(move |b| {
tx.send(b)
.map_err(|_| format_err!("mpsc receive error"))
.map(|_| ())
}).map_err(|_| ());
let _ = tokio::spawn(future);
rx
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment