Skip to content

Commit

Permalink
lib: un microtasks before ticks
Browse files Browse the repository at this point in the history
This resolve multiple timing issues related to promises
and nextTick. As well as resolving zaldo in promise only
code, i.e. our current best practice of using process.nextTick
will always apply and work.

Refs: nodejs#51156
Refs: nodejs#51156 (comment)
Refs: nodejs#51114
Refs: nodejs#51070
Refs: nodejs#51156

PR-URL: nodejs#51267
  • Loading branch information
ronag committed Dec 23, 2023
1 parent fc102f2 commit d95c4cb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/process/task_queues.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function runNextTicks() {
function processTicksAndRejections() {
let tock;
do {
runMicrotasks();
while ((tock = queue.shift()) !== null) {
const asyncId = tock[async_id_symbol];
emitBefore(asyncId, tock[trigger_async_id_symbol], tock);
Expand All @@ -92,7 +93,6 @@ function processTicksAndRejections() {

emitAfter(asyncId);
}
runMicrotasks();
} while (!queue.isEmpty() || processPromiseRejections());
setHasTickScheduled(false);
setHasRejectionToWarn(false);
Expand Down

0 comments on commit d95c4cb

Please sign in to comment.