compio_runtime::time

Function sleep

Source
pub async fn sleep(duration: Duration)
Available on crate feature time only.
Expand description

Waits until duration has elapsed.

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

To run something regularly on a schedule, see interval.

§Examples

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

use std::time::Duration;

use compio_runtime::time::sleep;

sleep(Duration::from_millis(100)).await;
println!("100 ms have elapsed");