LamportClock

A generic Lamport clock.

A Lamport clock is a simple logical clock that can be used to provide a causal ordering of events. Its potential disadvantage is that it may order concurrent events in a way that is undesirable for a given application.

This implementation is thread-safe.

Constructors

Link copied to clipboard
constructor(initialTime: LamportTimestamp, increment: (LamportTimestamp) -> LamportTimestamp, onNewTime: suspend (LamportTimestamp) -> Unit = {})

Properties

Link copied to clipboard
open override var lastTime: LamportTimestamp

The current logical timestamp of this clock.

Functions

Link copied to clipboard
open suspend override fun tick(): LamportTimestamp

Returns a logical timestamp that is greater than the current logical timestamp of this clock and updates the clock's internal state accordingly.

Link copied to clipboard
open suspend override fun tock(externalTime: LamportTimestamp): LamportTimestamp

Updates the internal state of the clock to reflect the occurrence of an external event with the given logical timestamp.