Advertisement
Guest User

Untitled

a guest
Aug 26th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. use std::time::{Duration, Instant};
  2. use tokio::prelude::*;
  3. use tokio::timer::Delay;
  4.  
  5. fn main() {
  6. let when = Instant::now() + Duration::from_millis(4000);
  7. let task = Delay::new(when)
  8. .and_then(|_| {
  9. println!("Hello world!");
  10. Ok(())
  11. })
  12. .map_err(|e| panic!("delay errored; err={:?}", e));
  13.  
  14. let future_with_timeout = task
  15. .timeout(Duration::from_millis(3000))
  16. .map_err(|e| println!("Timeout hit {:?}", e));
  17. let _ = future_with_timeout.wait().expect("Failure");
  18. // tokio::run(future_with_timeout);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement