pub trait TimeProvider: Clone {
// Required methods
fn sleep<'life0, 'async_trait>(
&'life0 self,
duration: Duration,
) -> Pin<Box<dyn Future<Output = SimulationResult<()>> + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn now(&self) -> Duration;
fn timer(&self) -> Duration;
fn timeout<'life0, 'async_trait, F, T>(
&'life0 self,
duration: Duration,
future: F,
) -> Pin<Box<dyn Future<Output = SimulationResult<Result<T, ()>>> + 'async_trait>>
where F: Future<Output = T> + 'async_trait,
T: 'async_trait,
Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Provider trait for time operations.
This trait allows code to work with both simulation time and real wall-clock time in a unified way. Implementations handle sleeping and getting current time appropriate for their environment.
§Time Semantics
now(): Returns the exact, canonical time. Use this for scheduling and precise comparisons.timer(): Returns a potentially drifted time that can be slightly ahead ofnow(). In simulation, this simulates real-world clock drift. In production, this equalsnow().
FDB ref: sim2.actor.cpp:1056-1064
Required Methods§
Sourcefn sleep<'life0, 'async_trait>(
&'life0 self,
duration: Duration,
) -> Pin<Box<dyn Future<Output = SimulationResult<()>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn sleep<'life0, 'async_trait>(
&'life0 self,
duration: Duration,
) -> Pin<Box<dyn Future<Output = SimulationResult<()>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Sleep for the specified duration.
In simulation, this advances simulation time. In real time, this uses actual wall-clock delays.
Sourcefn now(&self) -> Duration
fn now(&self) -> Duration
Get exact current time.
In simulation, this returns the canonical simulation time. In real time, this returns wall-clock elapsed time since provider creation.
Use this for precise time comparisons and event scheduling.
Sourcefn timer(&self) -> Duration
fn timer(&self) -> Duration
Get drifted timer time.
In simulation, this can be up to clock_drift_max (default 100ms) ahead of now().
This simulates real-world clock drift between processes.
In real time, this equals now().
Use this for time-sensitive application logic like timeouts, leases, and heartbeats to test how code handles clock drift.
FDB ref: sim2.actor.cpp:1058-1064
Sourcefn timeout<'life0, 'async_trait, F, T>(
&'life0 self,
duration: Duration,
future: F,
) -> Pin<Box<dyn Future<Output = SimulationResult<Result<T, ()>>> + 'async_trait>>where
F: Future<Output = T> + 'async_trait,
T: 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
fn timeout<'life0, 'async_trait, F, T>(
&'life0 self,
duration: Duration,
future: F,
) -> Pin<Box<dyn Future<Output = SimulationResult<Result<T, ()>>> + 'async_trait>>where
F: Future<Output = T> + 'async_trait,
T: 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
Run a future with a timeout.
Returns Ok(result) if the future completes within the timeout,
or Err(()) if it times out.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.