MCPcopy Index your code
hub / github.com/nodejs/node / tick

Method tick

lib/internal/test_runner/mock/mock_timers.js:696–720  ·  view source on GitHub ↗

* Advances the virtual time of MockTimers by the specified duration (in milliseconds). * This method simulates the passage of time and triggers any scheduled timers that are due. * @param {number} [time] - The amount of time (in milliseconds) to advance the virtual time. * @throws {ERR_INVA

(time = 1)

Source from the content-addressed store, hash-verified

694 * @throws {ERR_INVALID_ARG_VALUE} If a negative time value is provided.
695 */
696 tick(time = 1) {
697 this.#assertTimersAreEnabled();
698 this.#assertTimeArg(time);
699
700 this.#now += time;
701 let timer = this.#executionQueue.peek();
702 while (timer) {
703 if (timer.runAt > this.#now) break;
704 ReflectApply(timer.callback, undefined, timer.args);
705
706 // Check if the timeout was cleared by calling clearTimeout inside its own callback
707 const afterCallback = this.#executionQueue.peek();
708 if (afterCallback?.id === timer.id) {
709 this.#executionQueue.shift();
710 timer.priorityQueuePosition = undefined;
711 }
712
713 if (timer.interval !== undefined) {
714 timer.runAt += timer.interval;
715 this.#executionQueue.insert(timer);
716 }
717
718 timer = this.#executionQueue.peek();
719 }
720 }
721
722 /**
723 * @typedef {{apis: SupportedApis;now: number | Date;}} EnableOptions Options to enable the timers

Calls 5

#assertTimeArgMethod · 0.95
peekMethod · 0.45
shiftMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected