Skip to content

Commit a88c594

Browse files
committed
fixup
1 parent 0d9b9ca commit a88c594

File tree

1 file changed

+16
-57
lines changed

1 file changed

+16
-57
lines changed

lib/internal/process/task_queues.js

Lines changed: 16 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -56,63 +56,28 @@ function setHasTickScheduled(value) {
5656
const queue = new FixedQueue();
5757

5858
// Should be in sync with RunNextTicksNative in node_task_queue.cc
59-
function runNextTicksNew() {
59+
function runNextTicks() {
6060
if (!hasTickScheduled() && !hasRejectionToWarn())
6161
runMicrotasks();
6262
if (!hasTickScheduled() && !hasRejectionToWarn())
6363
return;
6464

65-
processTicksAndRejectionsNew();
65+
processTicksAndRejections();
6666
}
6767

68-
// Should be in sync with RunNextTicksNative in node_task_queue.cc
69-
function runNextTicksOld() {
70-
if (!hasTickScheduled() && !hasRejectionToWarn())
71-
runMicrotasks();
72-
if (!hasTickScheduled() && !hasRejectionToWarn())
73-
return;
74-
75-
processTicksAndRejectionsOld();
76-
}
77-
78-
function processTicksAndRejectionsOld() {
79-
let tock;
80-
do {
81-
while ((tock = queue.shift()) !== null) {
82-
const asyncId = tock[async_id_symbol];
83-
emitBefore(asyncId, tock[trigger_async_id_symbol], tock);
84-
85-
try {
86-
const callback = tock.callback;
87-
if (tock.args === undefined) {
88-
callback();
89-
} else {
90-
const args = tock.args;
91-
switch (args.length) {
92-
case 1: callback(args[0]); break;
93-
case 2: callback(args[0], args[1]); break;
94-
case 3: callback(args[0], args[1], args[2]); break;
95-
case 4: callback(args[0], args[1], args[2], args[3]); break;
96-
default: callback(...args);
97-
}
98-
}
99-
} finally {
100-
if (destroyHooksExist())
101-
emitDestroy(asyncId);
102-
}
103-
104-
emitAfter(asyncId);
68+
function processTicksAndRejections() {
69+
if (experimentalTaskOrdering === undefined) {
70+
if (experimentalTaskOrdering === undefined) {
71+
const { getOptionValue } = require('internal/options');
72+
experimentalTaskOrdering = getOptionValue('--experimental-task-ordering');
10573
}
106-
runMicrotasks();
107-
} while (!queue.isEmpty() || processPromiseRejections());
108-
setHasTickScheduled(false);
109-
setHasRejectionToWarn(false);
110-
}
74+
}
11175

112-
function processTicksAndRejectionsNew() {
11376
let tock;
11477
do {
115-
runMicrotasks();
78+
if (experimentalTaskOrdering) {
79+
runMicrotasks();
80+
}
11681
while ((tock = queue.shift()) !== null) {
11782
const asyncId = tock[async_id_symbol];
11883
emitBefore(asyncId, tock[trigger_async_id_symbol], tock);
@@ -138,6 +103,9 @@ function processTicksAndRejectionsNew() {
138103

139104
emitAfter(asyncId);
140105
}
106+
if (!experimentalTaskOrdering) {
107+
runMicrotasks();
108+
}
141109
} while (!queue.isEmpty() || processPromiseRejections());
142110
setHasTickScheduled(false);
143111
setHasRejectionToWarn(false);
@@ -205,23 +173,14 @@ function queueMicrotask(callback) {
205173

206174
module.exports = {
207175
setupTaskQueue() {
208-
if (experimentalTaskOrdering === undefined) {
209-
const { getOptionValue } = require('internal/options');
210-
experimentalTaskOrdering = getOptionValue('--experimental-task-ordering');
211-
}
212-
213176
// Sets the per-isolate promise rejection callback
214177
listenForRejections();
215178
// Sets the callback to be run in every tick.
216-
setTickCallback(experimentalTaskOrdering
217-
? processTicksAndRejectionsNew
218-
: processTicksAndRejectionsOld
179+
setTickCallback(processTicksAndRejections
219180
);
220181
return {
221182
nextTick,
222-
runNextTicks: experimentalTaskOrdering
223-
? runNextTicksNew
224-
: runNextTicksOld,
183+
runNextTicks
225184
};
226185
},
227186
queueMicrotask,

0 commit comments

Comments
 (0)