24 lines
457 B
Python
24 lines
457 B
Python
import time
|
|
import threading
|
|
|
|
|
|
class GlobalClock:
|
|
"""
|
|
Deterministic monotonic event clock.
|
|
Used for replay + ordering across distributed nodes.
|
|
"""
|
|
|
|
_lock = threading.Lock()
|
|
_counter = 0
|
|
|
|
@classmethod
|
|
def tick(cls) -> float:
|
|
with cls._lock:
|
|
cls._counter += 1
|
|
return time.time() + (cls._counter * 1e-9)
|
|
|
|
@classmethod
|
|
def reset(cls):
|
|
with cls._lock:
|
|
cls._counter = 0
|