pub fn interval(period: Duration) -> Interval
Available on crate feature
time
only.Expand description
Creates new Interval
that yields with interval of duration
. The first
tick completes immediately.
An interval will tick indefinitely. At any time, the Interval
value can be
dropped. This cancels the interval.
This function is equivalent to interval_at(Instant::now(), period)
.
§Panics
This function panics if period
is zero.
§Examples
use tokio::time::{self, Duration};
#[tokio::main]
async fn main() {
let mut interval = time::interval(Duration::from_millis(10));
interval.tick().await;
interval.tick().await;
interval.tick().await;
// approximately 20ms have elapsed.
}