Skip to main content

Clock

Trait Clock 

Source
pub trait Clock:
    Send
    + Sync
    + Debug {
    // Required methods
    fn now_utc(&self) -> OffsetDateTime;
    fn monotonic_ms(&self) -> i64;
    fn sleep<'life0, 'async_trait>(
        &'life0 self,
        duration: Duration,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn sleep_until_utc<'life0, 'async_trait>(
        &'life0 self,
        deadline: OffsetDateTime,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Unified clock abstraction.

All time observations and sleeps in production-facing Harn code should route through a Clock. Cron, the trigger dispatcher, the stdlib now_ms / sleep_ms builtins, and the OrchestratorHarness all accept Arc<dyn Clock> so test harnesses can swap in PausedClock.

Required Methods§

Source

fn now_utc(&self) -> OffsetDateTime

Current wall-clock UTC time.

Source

fn monotonic_ms(&self) -> i64

Monotonic milliseconds since an implementation-defined origin.

Required to be non-decreasing across calls on the same Clock instance. Used by the stdlib monotonic_ms / elapsed builtins and any code measuring durations across operations.

Source

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

Sleep for duration. No-op when duration is zero.

Source

fn sleep_until_utc<'life0, 'async_trait>( &'life0 self, deadline: OffsetDateTime, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Sleep until the wall-clock UTC deadline. No-op if deadline is in the past.

Implementors§