pub fn sleep(duration: Duration) -> Sleep<'static> ⓘ
Expand description
Returns a Future
that completes after the specified Duration
.
This function uses the global default timer, and the returned
Sleep
future will live for the 'static
lifetime. See the
module-level documentation for details on using the global default
timer.
§Panics
- If a global timer was not set by calling
set_global_timer
first. - If the provided duration exceeds the maximum sleep duration allowed by the global default timer.
For a version of this function that does not panic, see try_sleep()
instead.
§Examples
use maitake::time;
async fn example() {
time::sleep(time::Duration::from_secs(1)).await;
println!("one second has passed!");
}