Advances simulated time by ms, firing every callback whose due time falls within the
new interval, in ascending due-time order.
The number of milliseconds to advance.
Each callback runs at exactly its scheduled time; callbacks scheduled by other callbacks during advancement are honored if they become due within the same interval. After all due callbacks run, now equals the target time.
Cancels a scheduled callback.
The handle returned by setTimeout.
Returns the current simulated time.
The current time in milliseconds; changes only via advance.
Schedules fn to fire once simulated time reaches now() + ms.
The callback to invoke when due.
Delay in milliseconds; negative values are clamped to 0.
A numeric handle for clearTimeout.
A Clock whose time only moves when you call advance, for deterministic testing of time-dependent code.
Remarks
Scheduled callbacks fire during
advancein due-time order, mirroring real timer semantics without any wall-clock waiting.Example