Function tokio::time::interval_at

source ·
pub fn interval_at(start: Instant, period: Duration) -> Interval
Available on crate feature time only.
Expand description

Creates new Interval that yields with interval of period with the first tick completing at start. The default MissedTickBehavior is Burst, but this can be configured by calling set_missed_tick_behavior.

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


This function panics if period is zero.


use tokio::time::{interval_at, Duration, Instant};

async fn main() {
    let start = Instant::now() + Duration::from_millis(50);
    let mut interval = interval_at(start, Duration::from_millis(10));

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

    // approximately 70ms have elapsed.