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

###

    pub fn sleep(duration: Duration) -> SleepⓘNotable traits for Sleepimpl Future for Sleep    type Output = ();

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).

# Cancellation

Canceling a sleep instance 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::{sleep, Duration};

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