Skip to main content

Clock

Trait Clock 

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

Trait for time operations including getting current time and async sleeping.

This trait abstracts time operations, allowing mock implementations for deterministic testing of time-dependent logic.

Required Methods§

Source

fn now(&self) -> Instant

Get the current instant in time.

Source

fn timestamp(&self) -> u64

Get the current wall clock time in seconds since the Unix epoch.

Source

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

Async sleep for the given duration.

For production clocks, this actually waits for the specified duration. For mock clocks, this advances the simulated time and returns immediately.

Implementors§