Function tokio::time::sleep_until [−][src]
Expand description
Waits until deadline
is reached.
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
.
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_until, Instant, Duration};
#[tokio::main]
async fn main() {
sleep_until(Instant::now() + Duration::from_millis(100)).await;
println!("100 ms have elapsed");
}
See the documentation for the Sleep
type for more examples.