Function time::interval

Overview
async fn interval(period: Duration) -> Interval

Creates new Interval that yields with interval of period. The first tick completes immediately.

An interval will tick indefinitely. At any time, the Interval value can be dropped. This cancels the interval.

Examples

use time::Duration;

let duration = Duration::from_millis(10);
let interval = time::interval(duration);

interval.tick().await; // ticks immediately
interval.tick().await; // ticks after 10ms
interval.tick().await; // ticks after 10ms

println!("approximately 20ms have elapsed...");