speed defaults to 1; playing (default true) starts driving the clock right away.
True when nothing is scheduled: no deferred work and no pending timers.
Virtual time of the next timer, if any.
Number of pending tasks (deferred work + timers).
Whether real time is currently driving the clock.
Deferred work waiting to run now (e.g. queued external events).
Virtual ms per real ms (1 = real time, 0.5 = half speed).
Change the speed; negative values are treated as 0.
Advance by ms, running everything due.
Cancel a timer from setTimeout. Unknown or already-fired handles are ignored.
Like VirtualClock.defer, and notifies subscribers that work is queued.
Pause and drop every subscriber.
The current time in ms (real or virtual).
Stop time: nothing runs until play() or step().
Let real time drive the clock (at speed).
Runs deferred work, then fires timers in time order, advancing virtual
time, until nothing is pending or the next timer is later than until
(absolute virtual ms). Returns the number of tasks run.
Run exactly one task: the oldest deferred one, else the earliest timer (advancing virtual time to it). Returns false when nothing is pending.
Like VirtualClock.setTimeout, and notifies subscribers that work is queued.
Run tasks one at a time — jumping virtual time to the next timer when
nothing is ready — until until() holds after a task, or nothing is
pending. Pauses first. Returns the number of tasks run.
Called after every tick, play/pause, speed change and step, and when work is queued. Returns an unsubscribe function.
Play if paused, pause if playing.
A VirtualClock that real time drives forward — at an adjustable speed — and that can be paused and stepped. For visualisations: everything that takes its time from this clock (sessions, delayed sends, fake services, simulated environments) slows down, stops and single-steps together.
const clock = new PlaybackClock({ speed: 0.5 }); const session = await createSession(src, { clock }); clock.pause(); clock.step(); clock.play();