Function tokio::time::delay_for[][src]

pub fn delay_for(duration: Duration) -> Delay

Notable traits for Delay

impl Future for Delay type Output = ();

Waits until duration has elapsed.

Equivalent to delay_until(Instant::now() + duration). An asynchronous analog to std::thread::sleep.

No work is performed while awaiting on the delay to complete. The delay operates at millisecond granularity and should not be used for tasks that require high-resolution timers.

To run something regularly on a schedule, see interval.

Cancellation

Canceling a delay is done by dropping the returned future. No additional cleanup work is required.

Examples

Wait 100ms and print “100 ms have elapsed”.

use tokio::time::{delay_for, Duration};

#[tokio::main]
async fn main() {
    delay_for(Duration::from_millis(100)).await;
    println!("100 ms have elapsed");
}