pub struct HlcClock { /* private fields */ }Expand description
A thread-safe Hybrid Logical Clock.
Create one per process and share it across threads via Arc. Every call to
now produces a timestamp strictly greater than the last, and
every call to recv advances the clock past an incoming
remote timestamp — guaranteeing that your local clock always reflects
what it has “seen”.
Implementations§
Source§impl HlcClock
impl HlcClock
Sourcepub fn with_max_drift(max_drift: Duration) -> Self
pub fn with_max_drift(max_drift: Duration) -> Self
Create a new clock with a custom maximum drift.
Received timestamps whose physical component is more than max_drift
ahead of the local wall clock will be rejected with
HlcError::FutureDrift.
Sourcepub fn now(&self) -> Result<HlcTimestamp, HlcError>
pub fn now(&self) -> Result<HlcTimestamp, HlcError>
Generate a new timestamp for a local event or an outgoing message.
The returned timestamp is strictly greater than every timestamp previously produced by this clock instance.
Sourcepub fn recv(&self, msg: HlcTimestamp) -> Result<HlcTimestamp, HlcError>
pub fn recv(&self, msg: HlcTimestamp) -> Result<HlcTimestamp, HlcError>
Advance the clock upon receiving a message stamped with msg.
Returns the updated local timestamp. Attach this to any reply, or use it as the lower-bound for a consistent snapshot read.
§Errors
Returns HlcError::FutureDrift if msg.physical is more than
max_drift ahead of the local wall clock.
Sourcepub fn last(&self) -> HlcTimestamp
pub fn last(&self) -> HlcTimestamp
Return the last recorded timestamp without advancing the clock.