Skip to main content

Module time

Module time 

Source
Expand description

Time: sleeping, timeouts and intervals on the shard’s timer wheel. Time: sleeping, timeouts and intervals, on the timer wheel of the shard that polls them, and the runtime’s clock they read.

The clock is Instant. It runs with the system’s monotonic clock until pause stops it (or a runtime built with start_paused starts stopped); a paused clock moves only by advance, or by itself when every shard of its runtime is idle with a timer armed: it then jumps to the earliest timer, so code that sleeps runs at once in tests. Timers fire on the wheel’s millisecond: a timer waits at least its duration, rounded up to the next millisecond, and a shard busy with a task fires it once that task yields. sleep_precise waits to the microsecond instead, off the millisecond wheel: its deadline ends the shard’s wait through the backend’s high-resolution timer, and a paused clock moves to it exactly; sleep and timeout on the wheel pay nothing for it. Arming and cancelling a timer on its shard costs no allocation once the shard’s wheel has grown to the most timers alive at once; a timer polled on a thread that is not a shard (another runtime’s) is fired for it by a shard of the current runtime, or of the default one.

Modules§

error
The error of a timeout.

Structs§

Instant
A point in time on the clock of the runtime the code runs in.
Interval
Ticks at a fixed period. Made by interval and interval_at.
Sleep
A future that completes at its deadline. Made by sleep and sleep_until.
SleepPrecise
A future that completes at its deadline, to the microsecond. Made by sleep_precise and sleep_until_precise.
Timeout
A future with a deadline. Made by timeout and timeout_at.

Enums§

MissedTickBehavior
What an interval does with ticks it missed because it was polled late.

Functions§

advance
Moves the clock of the runtime this code runs in forward by duration, paused or running, then lets the timers that came due fire before it returns.
interval
Ticks every period, the first tick at once.
interval_at
Ticks every period, the first tick at start.
pause
Stops the clock of the runtime this code runs in (or of the default runtime): Instant::now stands still, and timers fire only as the clock is moved, by advance or by itself whenever every shard of the runtime is idle with a timer armed (it jumps to the earliest one). A paused clock stays paused.
resume
Starts a paused clock again from the time it stands at; a running clock goes on as it is.
sleep
Waits until duration has passed.
sleep_precise
Waits until duration has passed, to the microsecond.
sleep_until
Waits until deadline.
sleep_until_precise
Waits until deadline, to the microsecond (see sleep_precise).
timeout
Runs future for at most duration: its output, or Elapsed if the time ran out first. The future is polled before the clock is looked at, so one that is ready at once always wins.
timeout_at
Runs future until deadline at most; see timeout.