pub trait TimeProvider:
Clone
+ Send
+ Sync
+ 'static {
// Required methods
fn sleep(
&self,
duration: Duration,
) -> impl Future<Output = Result<(), TimeError>> + Send;
fn now(&self) -> Duration;
fn timer(&self) -> Duration;
fn timeout<F, T>(
&self,
duration: Duration,
future: F,
) -> impl Future<Output = Result<T, TimeError>> + Send
where F: Future<Output = T> + Send,
T: Send;
}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(
&self,
duration: Duration,
) -> impl Future<Output = Result<(), TimeError>> + Send
fn sleep( &self, duration: Duration, ) -> impl Future<Output = Result<(), TimeError>> + Send
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
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl TimeProvider for TokioTimeProvider
tokio-providers only.