pub struct Sleep { /* private fields */ }Expand description
Future returned by sleep.
§Examples
Wait 100ms and print “100 ms have elapsed”.
use ntex::time::{sleep, Millis};
#[ntex::main]
async fn main() {
sleep(Millis(100)).await;
println!("100 ms have elapsed");
}§Single waiter
A timer stores one waker. wait and
poll_elapsed take &self, but only the task that
polled most recently is woken when the timer elapses. Wait from one task at
a time; an earlier concurrent waiter may stay pending after the deadline.
The same applies to Deadline and TimerHandle.
Implementations§
Source§impl Sleep
impl Sleep
Sourcepub fn new(duration: Millis) -> Sleep ⓘ
pub fn new(duration: Millis) -> Sleep ⓘ
Creates a new sleep future.
A zero duration is rounded up to 1 ms.
Sourcepub fn is_elapsed(&self) -> bool
pub fn is_elapsed(&self) -> bool
Returns true if Sleep has elapsed.
Sourcepub fn reset<T>(&self, millis: T)
pub fn reset<T>(&self, millis: T)
Resets the Sleep instance to a new deadline.
Calling this function allows changing the instant at which the Sleep
future completes without having to create new associated state.
This function can be called both before and after the future has completed. A zero duration is rounded up to 1 ms.
Sourcepub async fn wait(&self)
pub async fn wait(&self)
Waits until this timer has elapsed.
Only one task may wait at a time; see single waiter.
Sourcepub fn poll_elapsed(&self, cx: &mut Context<'_>) -> Poll<()>
pub fn poll_elapsed(&self, cx: &mut Context<'_>) -> Poll<()>
Polls until this timer has elapsed.
A pending poll replaces the previously registered waker; see single waiter.