Function timeout
Source pub fn timeout(dur: Duration) -> Timeout
Expand description
Create a timeout tied to the current loop
This is a shortcut for:
ⓘTimeout::new(dur, &handle()).unwrap()
§Panics
When no loop is running (handle() panics)
(Note: while we technically unwrap() constructor it never fails in
current tokio)
8fn main() {
9
10 run(|| {
11 println!("Sleeping 1 second");
12 timeout(Duration::new(1, 0))
13 .and_then(|()| {
14 println!("Done");
15 Ok(())
16 })
17 }).unwrap();
18}