Documentation
¶
Overview ¶
Package hlc is a Hybrid Logical Clock: physical wall-clock milliseconds plus a logical counter. It orders events consistently across instances even when they are offline, reconnect at different times, or have clock skew - which a plain per-record version cannot do. Last-writer-wins conflict resolution compares (Wall, Counter) then breaks ties by writer id.
The physical clock is injectable, so a replay reproduces the same timestamps deterministically; the default is the system clock.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock issues monotonic HLC timestamps from an injectable physical clock. It is safe for concurrent use.
type Option ¶
type Option func(*Clock)
Option configures a Clock.
func WithPhysical ¶
WithPhysical sets the physical clock (default: clock.System).
type Time ¶
type Time struct {
Wall int64 // unix milliseconds
Counter uint16 // logical counter, disambiguating events within the same Wall
}
Time is an HLC timestamp. It is comparable by Wall then Counter; the zero value precedes every real timestamp.