Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate futures;
- extern crate tokio;
- use futures::{Async, Future, FutureExt, SinkExt};
- use futures::channel::mpsc::{Sender};
- use futures::channel::oneshot;
- fn foo(sender: Sender<Msg>) -> impl Future<Item = (), Error = ()> {
- let (s1, r1) = oneshot::channel::<u8>();
- // Send a command to the Raft, wait for the Raft to apply it
- // and get the result.
- println!("propose a request");
- let msg = Msg::Propose {
- id: 1,
- cb: Box::new(move || {
- s1.send(0);
- })
- };
- sender.send(msg)
- .map_err(|e| panic!("error {}", e))
- .and_then(|_| r1)
- .and_then(|n| {
- assert_eq!(n, 0);
- println!("receive the propose callback");
- Ok(Async::Ready(()))
- })
- .map(|_| ())
- .map_err(|_| ())
- }
- enum Msg {
- Propose { id: u8, cb: Box<Fn() + Send> },
- }
- fn main() {
- println!("hello, world");
- }
Add Comment
Please, Sign In to add comment