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
intervalandinterval_at. - Sleep
- A future that completes at its deadline. Made by
sleepandsleep_until. - Sleep
Precise - A future that completes at its deadline, to the microsecond. Made by
sleep_preciseandsleep_until_precise. - Timeout
- A future with a deadline. Made by
timeoutandtimeout_at.
Enums§
- Missed
Tick Behavior - 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 atstart. - pause
- Stops the clock of the runtime this code runs in (or of the default
runtime):
Instant::nowstands still, and timers fire only as the clock is moved, byadvanceor 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
durationhas passed. - sleep_
precise - Waits until
durationhas passed, to the microsecond. - sleep_
until - Waits until
deadline. - sleep_
until_ precise - Waits until
deadline, to the microsecond (seesleep_precise). - timeout
- Runs
futurefor at mostduration: its output, orElapsedif 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
futureuntildeadlineat most; seetimeout.