Skip to content
CryoCryo home
Stdlibfuture

timer

import std::future::timer; · source

Types

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.

Properties

PropertyType
deadlinei64
idu64
rtReactor*

Constructors

static new(dur: Duration) -> Sleep;

Complete once dur has elapsed from now. A zero (or already-elapsed) duration completes on the first poll without touching the reactor.

static until(deadline: Instant) -> Sleep;

Complete at deadline on the monotonic clock. A deadline already in the past completes on the first poll.

Methods

deadline_nanos(&this) -> i64;

The instant this sleep is due, in the raw monotonic nanoseconds the reactor's deadline chain is keyed on.

is_elapsed(&this) -> boolean;

True once the deadline has passed, whether or not this future has been polled since.

Trait implementations

implement trait Future for struct Sleep
implement trait Drop for struct Sleep

Constants

const DEADLINE_MAX:      i64 = 9223372036854775807;
const DEADLINE_MAX_SECS: u64 = 9223372036;