Expand description

Timer implementation.

This module contains the types needed to run a timer.

The Timer type runs the timer logic. It holds all the necessary state to track all associated Delay instances and delivering notifications once the deadlines are reached.

The Handle type is a reference to a Timer instance. This type is Clone, Send, and Sync. This type is used to create instances of Delay.

The Now trait describes how to get an Instant representing the current moment in time. SystemNow is the default implementation, where Now::now is implemented by calling Instant::now.

Timer is generic over Now. This allows the source of time to be customized. This ability is especially useful in tests and any environment where determinism is necessary.

Note, when using the Tokio runtime, the Timer does not need to be manually setup as the runtime comes pre-configured with a Timer instance.

Structs

A guard that resets the current timer to None when dropped.

Handle to timer instance.

A handle to a source of time.

Timer implementation that drives Delay, Interval, and Timeout.

Return value from the turn method on Timer.

Functions

Sets handle as the default timer, returning a guard that unsets it on drop.

Set the default timer for the duration of the closure.