Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::time::{Duration, Instant};
- use tokio::prelude::*;
- use tokio::timer::Delay;
- fn main() {
- let when = Instant::now() + Duration::from_millis(4000);
- let task = Delay::new(when)
- .and_then(|_| {
- println!("Hello world!");
- Ok(())
- })
- .map_err(|e| panic!("delay errored; err={:?}", e));
- let future_with_timeout = task
- .timeout(Duration::from_millis(3000))
- .map_err(|e| println!("Timeout hit {:?}", e));
- let _ = future_with_timeout.wait().expect("Failure");
- // tokio::run(future_with_timeout);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement