-
-
Save tobz/0d6d5d4b2672d96910857e5b717a4854 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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