foundationdb::env

Trait Clock

Source
pub trait Clock:
    Debug
    + Send
    + Sync {
    // Required methods
    fn monotonic(&self) -> Duration;
    fn wall(&self) -> Duration;
}
Expand description

Where time comes from.

See the module documentation for why time is a dependency rather than something to reach for, and for the rule that decides between the two readings: measure with monotonic, persist with wall.

Required Methods§

Source

fn monotonic(&self) -> Duration

A monotonic reading, for measuring how much time has passed.

Successive readings never decrease, which makes this the reading to use for elapsed times, deadlines, budgets and backoff.

The epoch is arbitrary and private to this instance. Never persist a monotonic reading, and never compare readings taken from two different Clock instances: only the difference between two readings of the same instance carries meaning.

Source

fn wall(&self) -> Duration

A wall-clock reading, time elapsed since the UNIX epoch.

This is a real timestamp, comparable across processes and machines, so it is the reading to persist in the database or put in a message. In production it can jump forwards or backwards when the machine clock is adjusted (NTP, a leap second, an operator), so never measure a duration with it. Under simulation it is deterministic.

Implementors§