Skip to content

Commit 3a1c141

Browse files
committed
fixup
1 parent 0d9b9ca commit 3a1c141

File tree

1 file changed

+14
-57
lines changed

1 file changed

+14
-57
lines changed

lib/internal/process/task_queues.js

Lines changed: 14 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -56,63 +56,26 @@ 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-
}
68+
function processTicksAndRejections() {
69+
if (experimentalTaskOrdering === undefined) {
70+
const { getOptionValue } = require('internal/options');
71+
experimentalTaskOrdering = getOptionValue('--experimental-task-ordering');
72+
}
7773

78-
function processTicksAndRejectionsOld() {
7974
let tock;
8075
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);
76+
if (experimentalTaskOrdering) {
77+
runMicrotasks();
10578
}
106-
runMicrotasks();
107-
} while (!queue.isEmpty() || processPromiseRejections());
108-
setHasTickScheduled(false);
109-
setHasRejectionToWarn(false);
110-
}
111-
112-
function processTicksAndRejectionsNew() {
113-
let tock;
114-
do {
115-
runMicrotasks();
11679
while ((tock = queue.shift()) !== null) {
11780
const asyncId = tock[async_id_symbol];
11881
emitBefore(asyncId, tock[trigger_async_id_symbol], tock);
@@ -138,6 +101,9 @@ function processTicksAndRejectionsNew() {
138101

139102
emitAfter(asyncId);
140103
}
104+
if (!experimentalTaskOrdering) {
105+
runMicrotasks();
106+
}
141107
} while (!queue.isEmpty() || processPromiseRejections());
142108
setHasTickScheduled(false);
143109
setHasRejectionToWarn(false);
@@ -205,23 +171,14 @@ function queueMicrotask(callback) {
205171

206172
module.exports = {
207173
setupTaskQueue() {
208-
if (experimentalTaskOrdering === undefined) {
209-
const { getOptionValue } = require('internal/options');
210-
experimentalTaskOrdering = getOptionValue('--experimental-task-ordering');
211-
}
212-
213174
// Sets the per-isolate promise rejection callback
214175
listenForRejections();
215176
// Sets the callback to be run in every tick.
216-
setTickCallback(experimentalTaskOrdering
217-
? processTicksAndRejectionsNew
218-
: processTicksAndRejectionsOld
177+
setTickCallback(processTicksAndRejections
219178
);
220179
return {
221180
nextTick,
222-
runNextTicks: experimentalTaskOrdering
223-
? runNextTicksNew
224-
: runNextTicksOld,
181+
runNextTicks
225182
};
226183
},
227184
queueMicrotask,

0 commit comments

Comments
 (0)