Expand description
Thread-pool timers: CreateThreadpoolTimer / SetThreadpoolTimer /
WaitForThreadpoolTimerCallbacks / CloseThreadpoolTimer.
Two types share this machinery, and they differ in the one property that matters when writing the callback:
ThreadpoolTimerfires exactly once per arming, and re-arming from inside its own callback is applied only after that callback returns, so repetition driven that way never overlaps itself.ThreadpoolPeriodicTimerrepeats on a fixed period, and the pool may queue the next callback while the previous one is still running. Its callback must tolerate overlapping with itself.
The platform models both with one object and a period argument. This crate
separates them so that concurrency contract belongs to a type rather than to
an argument that is easy to skim past.
§Choosing between them
Want a fixed cadence, and the callback is short or safe to overlap? Use
ThreadpoolPeriodicTimer. Want the next delay measured from when the previous
callback finished, with no overlap possible? Use a ThreadpoolTimer and re-arm it
from inside its own callback with TimerFiring::rearm_after.
§Due times
Relative due times (ThreadpoolTimer::set_after) count only time the system is
awake, so sleep and hibernation do not consume the delay. Absolute due times
(ThreadpoolTimer::set_at) name a wall-clock instant, which sleep and hibernation
do pass through: a timer set for an instant that elapsed while the machine
slept fires promptly on resume.
Structs§
- Periodic
Tick - One tick of a
ThreadpoolPeriodicTimer, handed to its callback. - Threadpool
Periodic Timer - An owned repeating thread-pool timer.
- Threadpool
Timer - An owned one-shot thread-pool timer.
- Timer
Firing - One firing of a
ThreadpoolTimer, handed to its callback.