1/** @Log.Clock.Seam — where event timestamps come from */2modulePuduLangLog.Clock34importStd.SyncasSync5importStd.TimeasTime6importPuduLangLogasLog78/** @Log.Clock.Source — a function answering the current moment */9exporttypeClock = fn() -> Log.Timestamp1011/// The system clock with the machine's current offset.12exportfnsystem() -> Clock {13fn() -> Log.Timestamp { Log.Timestamp{millis: Time.toMillis(&Time.currentInstant()), offset: Time.localOffsetMinutes()} }14}1516/// The system clock at offset zero.17exportfnutc() -> Clock {18fn() -> Log.Timestamp { Log.Timestamp{millis: Time.toMillis(&Time.currentInstant()), offset: 0} }19}2021/// A clock that always answers the same moment.22exportfnfixed(moment: Log.Timestamp) -> Clock { fn() -> Log.Timestamp { moment } }2324/// A clock that starts at a moment and advances by `step` milliseconds on every reading.25exportfnstepping(start: Log.Timestamp, step: Int) -> Clock {26let next = Sync.cell(start.millis)27let lock = Sync.mutex()28fn() -> Log.Timestamp {29let taken = Sync.withLock(&lock, fn() -> Int {30let current = matchSync.get(&next) {31caseOk(value) => value32caseErr(_) => start.millis33 }34let _stored = Sync.set(&next, current + step)35 current36 })37match taken {38caseOk(millis) => Log.Timestamp{millis: millis, offset: start.offset}39caseErr(_) => start40 }41 }42}43