Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Jun 19th, 2018 45 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top