Expand description
OS-backed timers for Tokio.
The active backends are:
- Linux and Android:
timerfd. - Windows: a high-resolution waitable timer when supported, with a standard waitable-timer fallback on older Windows versions.
- macOS, iOS, and BSD:
kqueuewithEVFILT_TIMER; NetBSD and OpenBSD currently fall back to millisecond granularity. - Other platforms: a Tokio timer-wheel fallback.
“High resolution” describes the operating-system timer facility and the granularity it can represent; it is not a promise that a task is polled at the requested deadline. Resolution is only the timer’s representable step:
- Deadline error is the difference between the actual and requested wakeup. It includes timer delivery, OS scheduling, task wakeup, and load.
- Jitter is variation in that error between wakeups. Low jitter does not imply low absolute latency.
- Drift is accumulated error over repeated periods.
Intervalre-arms against an absolute schedule to avoid unbounded drift, but it cannot remove scheduler-induced latency.
These APIs do not provide hard real-time guarantees.
Delay: a future that completes at a specified instant.Interval: a stream that yields at fixed intervals.DelayQueue: a queue that multiplexes many deadlines over one timer.sleepandtry_sleep: convenience functions that create aDelay.
Timer constructors must be called while a Tokio runtime is active.
On Linux, the realtime and boottime features select an alternative
timerfd clock. With neither feature enabled, the monotonic clock is used.
These features have no effect on other platforms.
Structs§
- Delay
- A future that completes at a specified instant.
- Delay
Queue - A queue of values that become available after their deadlines elapse.
- Expired
- An entry returned after its deadline has elapsed.
- Interval
- A stream that yields at fixed intervals.
- Key
- Identifies an entry stored in a
DelayQueue. - TimerFd
- A low-level Linux
timerfdintegrated with the Tokio reactor.