Skip to main content

Clock

Trait Clock 

Source
pub trait Clock {
    // Required methods
    fn current_time(&self) -> Timestamp;
    fn sleep_until<'life0, 'async_trait>(
        &'life0 self,
        timestamp: Timestamp,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn sleep_for<'life0, 'async_trait>(
        &'life0 self,
        duration: Duration,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

A clock that can be used to get the current Timestamp.

Required Methods§

Source

fn current_time(&self) -> Timestamp

Returns the current time.

Source

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

Waits until the given timestamp is reached.

Provided Methods§

Source

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

Waits for the given duration, measured against this clock.

Unlike linera_base::time::timer::sleep, this honors a simulated clock (e.g. a test clock), so callers that sleep through it can be driven deterministically in virtual time.

Implementors§