Sign in

    moonbitstack/moonzero/clock does not have a README file

    Clock

    pub struct Clock {
    now_ms : () -> Int64
    }

    A 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. go-zero 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.

    Clock::new

    fn Clock::new(now_ms : () -> Int64) -> Clock

    Wrap a now-in-milliseconds thunk as a Clock.

    Clock::now

    fn Clock::now(self : Clock) -> Int64

    The current time in milliseconds, as reported by the wrapped source.

    Clock::system

    fn Clock::system() -> Clock

    The platform clock, in milliseconds since the Unix epoch (← go-zero's timex.Now()). Every backend can read it, so a service that has no reason to inject its own time source can take this one.

    ManualClock

    pub struct ManualClock {
    ms : Int64
    }

    A 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.

    ManualClock::advance

    fn ManualClock::advance(self : ManualClock, delta : Int64) -> Unit

    Move the manual clock forward by delta milliseconds.

    ManualClock::as_clock

    fn ManualClock::as_clock(self : ManualClock) -> Clock

    A Clock view over this manual clock: reading it reflects every advance.

    ManualClock::new

    fn ManualClock::new(start? : Int64) -> ManualClock

    A manual clock starting at start milliseconds (default 0).

    Source Files