interval

Function interval 

Source
pub fn interval(dur: Duration) -> Interval
Expand description

Create an interval tied to the current loop

This is a shortcut for:

Interval::new(instant, &handle()).unwrap()

§Panics

When no loop is running (handle() panics)

(Note: while we technically unwrap() constructor it never fails in current tokio)

Examples found in repository?
examples/two_intervals.rs (line 11)
8fn main() {
9
10    run_forever(|| {
11        spawn(interval(Duration::new(1, 0))
12            .for_each(|()| {
13                println!("1 sec interval");
14                Ok(())
15            }).map_err(|_| ()));
16        spawn(interval(Duration::from_millis(500))
17            .for_each(|()| {
18                println!("Half second interval");
19                Ok(())
20            }).map_err(|_| ()));
21        Ok::<_, ()>(())
22    }).unwrap();
23}