pub trait Clock:
Debug
+ Send
+ Sync {
// Required methods
fn now(&self) -> SystemTime;
fn sleep<'life0, 'async_trait>(
&'life0 self,
dur: Duration,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided method
fn jitter_frac(&self) -> f64 { ... }
}Expand description
The turn’s clock and jitter source — its only non-determinism.
The retry backoff is the sole place the turn loop reads wall time (for jitter
entropy) or waits (for the backoff), so routing both through an injected
capability makes a whole turn deterministically replayable: production wires
the real clock (RealClock) and behaves exactly as before, while a test
wires a virtual clock with a fixed jitter seed and gets byte-identical output
it can step without a wall-clock wait.
Required Methods§
Sourcefn now(&self) -> SystemTime
fn now(&self) -> SystemTime
The current wall-clock time.
Sourcefn sleep<'life0, 'async_trait>(
&'life0 self,
dur: Duration,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn sleep<'life0, 'async_trait>(
&'life0 self,
dur: Duration,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Wait for dur before the caller retries.
§Cancellation
Cancellation-safe: dropping the returned future cancels the wait with no observable effect, exactly like the underlying timer.
Provided Methods§
Sourcefn jitter_frac(&self) -> f64
fn jitter_frac(&self) -> f64
A jitter fraction in [0, 1) used to spread retries (equal jitter in
backoff_delay). The exact value only matters for the spread, so the
default derives it from Self::now — the same cheap clock read the
retry path used before the seam existed. A deterministic clock overrides
this with a seeded draw so a replay reproduces the same spacing.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".