ClockProvider

Trait ClockProvider 

Source
pub trait ClockProvider: Send + Sync {
    // Required methods
    fn now(&self) -> u64;
    fn system_time_millis(&self) -> u64;
    fn sleep(
        &self,
        duration: Duration,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + '_>>;
    fn advance(&self, duration: Duration);
    fn is_mock(&self) -> bool;
}
Expand description

Provider trait for time operations.

This trait abstracts all time-related operations, allowing tests to control time precisely for deterministic behavior.

Required Methods§

Source

fn now(&self) -> u64

Get a monotonic instant (for measuring durations).

Source

fn system_time_millis(&self) -> u64

Get the current system time as milliseconds since UNIX epoch.

Source

fn sleep( &self, duration: Duration, ) -> Pin<Box<dyn Future<Output = ()> + Send + '_>>

Sleep for the specified duration.

In mock implementations, this may return immediately or track pending sleeps for manual advancement.

Source

fn advance(&self, duration: Duration)

Advance time by the specified duration (mock-only operation).

Real implementations should do nothing.

Source

fn is_mock(&self) -> bool

Check if this is a mock clock.

Implementors§