Expand description
Injectable wall clocks, monotonic clocks, and deterministic timers.
Wall time and monotonic time are deliberately separate. Long-lived
services can inject WallClock for business timestamps, while timeout
and delay code injects MonotonicClock or Timer. A
BlockingSleeper can adapt the same timer when synchronous code must
block, provided the timer backend can progress while the calling thread is
parked. Manual implementations allow tests to advance logical time without
waiting for real time to pass.
§Examples
A manual timer can drive a blocking sleep without waiting for real time:
use qubit_clock::{
BlockingSleeper, ManualMonotonicClock, MonotonicClock,
};
use std::time::Duration;
let clock = ManualMonotonicClock::new_shared();
let sleeper = BlockingSleeper::new(clock.new_timer());
let worker = std::thread::spawn(move || {
sleeper
.sleep_for(Duration::from_secs(5))
.expect("manual sleep should complete");
});
assert!(clock.wait_for_waiters(1, Duration::from_secs(1)));
clock
.advance(Duration::from_secs(5))
.expect("manual time should advance");
worker.join().expect("sleeping thread should finish");Re-exports§
pub use error::TokioRuntimeError;tokiopub use error::TimeError;pub use monotonic::ClockDomain;pub use monotonic::ManualDeadlineFuture;pub use monotonic::ManualMonotonicClock;pub use monotonic::ManualWaiterFuture;pub use monotonic::MonotonicClock;pub use monotonic::MonotonicInstant;pub use monotonic::StdMonotonicClock;pub use sleep::BlockingSleeper;pub use timer::ManualTimer;pub use timer::StdTimer;pub use timer::Timer;pub use timer::TimerFuture;pub use wall::FixedWallClock;pub use wall::ManualWallClock;pub use wall::StdWallClock;pub use wall::WallClock;pub use monotonic::TokioMonotonicClock;tokiopub use timer::TokioTimer;tokio
Modules§
- error
- Error types exposed by this crate.
- monotonic
- Monotonic clocks and domain-scoped instants.
- sleep
- Blocking adaptation over asynchronous monotonic timers.
- test_
util test-util - Test-only Timer implementations for deterministic failure injection.
- timer
- Timer capabilities for asynchronous deadline notification.
- wall
- Wall-clock abstractions and implementations.