08 / CONTROL
clock
A millisecond time source injected into the resilience middlewares so their timing is a pure function of an explicit clock; ManualClock drives them deterministically in tests.
WHERE IT SITS
INTERFACE
struct ClockstructA monotonic time source in **milliseconds**, injected into the resilience middlewares (rate-limit, breaker, timeout) so their timing logic is a pure function of an explicit clock rather than a hidden wall-clock read. reads timex.Now() directly; because that is neither portable across MoonBit's backends nor testable, moonzero threads the clock as a value — the same pattern Go's clockwork/x/time/rate accept for a Clock.
fn Clock::new(now_ms : () -> Int64) -> ClockfnWrap a now-in-milliseconds thunk as a Clock.
fn Clock::now(self : Clock) -> Int64fnThe current time in milliseconds, as reported by the wrapped source.
fn Clock::system() -> ClockfnThe platform clock, in milliseconds since the Unix epoch`). Every backend can read it, so a service that has no reason to inject its own time source can take this one.
struct ManualClockstructA deterministic, hand-advanced clock for tests and for driving the rate-limit / breaker cores without a real time source. Wall time is replaced by an explicit advance, so a token bucket's refill or a breaker's open window can be exercised exactly.
fn ManualClock::new(start~ : Int64 = 0) -> ManualClockfnA manual clock starting at start milliseconds (default 0).
fn ManualClock::advance(self : ManualClock, delta : Int64) -> UnitfnMove the manual clock forward by delta milliseconds.
fn ManualClock::as_clock(self : ManualClock) -> ClockfnA Clock view over this manual clock: reading it reflects every advance.