timer
import std::future::timer; · source
Sleep
type struct Sleep {
deadline: i64;
id: u64;
rt: Reactor*;
static new(dur: Duration) -> Sleep;
static until(deadline: Instant) -> Sleep;
deadline_nanos(&this) -> i64;
is_elapsed(&this) -> boolean;
}
The timer counterpart of an I/O future. Instead of asking the reactor to wake it when a descriptor becomes ready, it asks to be woken at a point on the monotonic clock. The reactor keeps those deadlines in a sorted chain and bounds its readiness wait by the earliest one, so a sleeping task costs no thread and no polling — the wait the reactor was already in simply ends sooner.
Deadlines are absolute, not durations: Sleep::new(dur) resolves dur against the clock once, at construction. A Sleep polled late, or polled many times, still completes at the instant it was created to complete at, and re-polling never extends it.
Dropping a Sleep disarms its registration. That is what makes it usable as the losing half of a select — the timer that did not win is dropped and its waker released immediately, rather than lingering until the deadline passes.
Trait implementations
implement trait Future for struct Sleep
implement trait Drop for struct Sleep