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

Function processTicksAndRejections

lib/internal/process/task_queues.js:72–109  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

70}
71
72function processTicksAndRejections() {
73 let tock;
74 do {
75 while ((tock = queue.shift()) !== null) {
76 const priorContextFrame =
77 AsyncContextFrame.exchange(tock[async_context_frame]);
78
79 const asyncId = tock[async_id_symbol];
80 emitBefore(asyncId, tock[trigger_async_id_symbol], tock);
81
82 try {
83 const callback = tock.callback;
84 if (tock.args === undefined) {
85 callback();
86 } else {
87 const args = tock.args;
88 switch (args.length) {
89 case 1: callback(args[0]); break;
90 case 2: callback(args[0], args[1]); break;
91 case 3: callback(args[0], args[1], args[2]); break;
92 case 4: callback(args[0], args[1], args[2], args[3]); break;
93 default: callback(...args);
94 }
95 }
96 } finally {
97 emitDestroy(asyncId);
98 }
99
100 emitAfter(asyncId);
101
102 AsyncContextFrame.set(priorContextFrame);
103 }
104 runMicrotasks();
105 } while (!queue.isEmpty() ||
106 (hasRejectionToWarn() && processPromiseRejections()));
107 setHasTickScheduled(false);
108 setHasRejectionToWarn(false);
109}
110
111// `nextTick()` will not enqueue any callback when the process is about to
112// exit since the callback would not have a chance to be executed.

Callers 1

runNextTicksFunction · 0.85

Calls 9

hasRejectionToWarnFunction · 0.85
processPromiseRejectionsFunction · 0.85
setHasTickScheduledFunction · 0.85
setHasRejectionToWarnFunction · 0.85
callbackFunction · 0.50
shiftMethod · 0.45
exchangeMethod · 0.45
setMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…