RTCForge API Reference v1.1.1
    Preparing search index...

    Class ManualClock

    A Clock whose time only moves when you call advance, for deterministic testing of time-dependent code.

    Scheduled callbacks fire during advance in due-time order, mirroring real timer semantics without any wall-clock waiting.

    const clock = new ManualClock()
    let fired = false
    clock.setTimeout(() => { fired = true }, 1000)
    clock.advance(999) // fired === false
    clock.advance(1) // fired === true

    Implements

    Index

    Constructors

    Methods

    • Advances simulated time by ms, firing every callback whose due time falls within the new interval, in ascending due-time order.

      Parameters

      • ms: number

        The number of milliseconds to advance.

      Returns void

      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.

    • Schedules fn to fire once simulated time reaches now() + ms.

      Parameters

      • fn: () => void

        The callback to invoke when due.

      • ms: number

        Delay in milliseconds; negative values are clamped to 0.

      Returns unknown

      A numeric handle for clearTimeout.