Guest User

Untitled

a guest
Jun 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. extern crate futures;
  2. extern crate tokio;
  3.  
  4. use futures::{Async, Future, FutureExt, SinkExt};
  5. use futures::channel::mpsc::{Sender};
  6. use futures::channel::oneshot;
  7.  
  8. fn foo(sender: Sender<Msg>) -> impl Future<Item = (), Error = ()> {
  9. let (s1, r1) = oneshot::channel::<u8>();
  10. // Send a command to the Raft, wait for the Raft to apply it
  11. // and get the result.
  12. println!("propose a request");
  13. let msg = Msg::Propose {
  14. id: 1,
  15. cb: Box::new(move || {
  16. s1.send(0);
  17. })
  18. };
  19.  
  20. sender.send(msg)
  21. .map_err(|e| panic!("error {}", e))
  22. .and_then(|_| r1)
  23. .and_then(|n| {
  24. assert_eq!(n, 0);
  25. println!("receive the propose callback");
  26. Ok(Async::Ready(()))
  27. })
  28. .map(|_| ())
  29. .map_err(|_| ())
  30. }
  31.  
  32. enum Msg {
  33. Propose { id: u8, cb: Box<Fn() + Send> },
  34. }
  35.  
  36. fn main() {
  37. println!("hello, world");
  38. }
Add Comment
Please, Sign In to add comment