Expand description
Infrastructure for integrating time primitives into async runtimes.
This module provides the necessary components to bridge time-based operations with async runtime execution. The primary workflow involves:
- Start with an
InactiveClockthat can be safely moved across threads - Activate it using
InactiveClock::activateto get aClockandClockDriver - Use the
ClockDriverto periodically advance timers in your runtime loop - Use the
Clockfor time operations like creating timers and measuring time
§Integration with Runtimes
Different runtime architectures can integrate this module as follows:
§Single-threaded Runtimes
Clone the InactiveClock before moving it to each thread, then activate
separately to avoid lock contention:
let inactive = InactiveClock::default();
let inactive_clone = inactive.clone();
// On thread 1
let (clock1, driver1) = inactive.activate();
// On thread 2
let (clock2, driver2) = inactive_clone.activate();§Multi-threaded Runtimes
Activate once and share the clock across threads, keeping the driver on the main runtime thread for timer advancement.
Structs§
- Clock
Driver - Drives timer advancement for the clock.
- Clock
Gone - Error returned when all owners of a clock have been dropped.
- Inactive
Clock - An inactive clock that must be activated before time operations can be performed.