Skip to main content

Clock

Trait Clock 

Source
pub trait Clock:
    Send
    + Sync
    + Debug {
    // Required methods
    fn now(&self) -> Instant;
    fn timestamp_ms(&self) -> u64;
    fn timestamp_rfc3339(&self) -> String;
    fn timestamp_datetime(&self) -> DateTime<Utc>;
    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<'life0, 'async_trait>(
        &'life0 self,
        deadline: Instant,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Runtime time source. Cloneable as Arc<dyn Clock>; carried on RuntimeHostConfig.

Required Methods§

Source

fn now(&self) -> Instant

Monotonic instant for measuring elapsed time. Never persisted.

Source

fn timestamp_ms(&self) -> u64

Wall-clock time as epoch milliseconds, for durable records.

Source

fn timestamp_rfc3339(&self) -> String

Wall-clock time as an RFC 3339 string, for durable records.

Source

fn timestamp_datetime(&self) -> DateTime<Utc>

Wall-clock time as a UTC datetime, for trace records.

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. Replaces tokio::time::sleep.

Source

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

Sleep until deadline (a value from now). Replaces tokio::time::sleep_until.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§