pub struct HlcGenerator { /* private fields */ }Expand description
Issues monotonically increasing HLCs for one device, folding in the highest HLC observed from remote ops so causality survives clock skew.
Implementations§
Source§impl HlcGenerator
impl HlcGenerator
Sourcepub fn new(device_id: impl Into<String>) -> Self
pub fn new(device_id: impl Into<String>) -> Self
A generator for device_id starting at wall time zero.
Sourcepub fn next(&self, clock: &dyn Clock) -> Hlc
pub fn next(&self, clock: &dyn Clock) -> Hlc
Issue the next HLC, strictly greater than every previous one issued or
observed, using clock for the wall component.
Negative clock readings are clamped to 0 (the sortable encoding is
only order-preserving for non-negative wall times — see Clock);
if the logical counter is exhausted under a stalled clock, the wall
component advances logically instead (HLC semantics permit the wall
to run ahead of the physical clock).
Sourcepub fn observe(&self, remote: &Hlc)
pub fn observe(&self, remote: &Hlc)
Fold in an HLC observed from a remote op so subsequently issued HLCs
sort after it. Negative remote wall times are ignored (they are
rejected at ingest by crate::Grit::apply_remote).