Function tokio::time::sleep[][src]

pub fn sleep(duration: Duration) -> Sleep

Notable traits for Sleep

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

Waits until duration has elapsed.

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

No work is performed while awaiting on the sleep future to complete. Sleep 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.

The maximum duration for a sleep is 68719476734 milliseconds (approximately 2.2 years).


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


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

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

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