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

pub fn delay_for(duration: Duration) -> Delay

Important traits for Delay

impl Future for Delay type Output = ();
This is supported on feature="time" only.

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.


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


Wait 100ms and print "100 ms have elapsed".

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

async fn main() {
    println!("100 ms have elapsed");