Fief.Sim.ManualClock (Fief v0.1.0)

Copy Markdown View Source

A steppable virtual clock for tests: time advances only via advance/2.

Backs Fief.Seam.Sim for processes bound with Fief.Sim.bind_clock/1. Timers armed through it deliver {:timeout, ref, msg} — the same shape as Fief.Seam.Real — when advance/2 moves the clock past their deadline, in deadline order.

Several clocks may coexist (per-node virtual clocks skewed against the arbiter's clock, per design §6.4 / implementation.md §3.2). For simulations that need an event queue — quiescence-gated advance, per-node skew, timer firings as scripted events — use Fief.Sim.Scheduler, which implements this module's call contract itself; ManualClock stays as the lightweight clock-only hook.

Summary

Functions

Advance virtual time by ms, firing due timers in deadline order. Timer messages are sent before advance/2 returns, but delivery interleaving with other senders is the receiver's mailbox order as usual.

Cancel a virtual timer. Returns remaining ms or false if already fired.

Returns a specification to start this module under a supervisor.

Current virtual monotonic time, milliseconds.

Arm a virtual timer; delivers {:timeout, ref, msg} to dest when due.

Types

t()

@type t() :: GenServer.server()

Functions

advance(clock, ms)

@spec advance(t(), non_neg_integer()) :: :ok

Advance virtual time by ms, firing due timers in deadline order. Timer messages are sent before advance/2 returns, but delivery interleaving with other senders is the receiver's mailbox order as usual.

cancel_timer(clock, ref)

@spec cancel_timer(t(), reference()) :: non_neg_integer() | false

Cancel a virtual timer. Returns remaining ms or false if already fired.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

monotonic_time(clock)

@spec monotonic_time(t()) :: integer()

Current virtual monotonic time, milliseconds.

send_after(clock, dest, ms, msg)

@spec send_after(t(), pid(), non_neg_integer(), term()) :: reference()

Arm a virtual timer; delivers {:timeout, ref, msg} to dest when due.

start_link(opts \\ [])