From 440ff338ddb97add9d3e9ddbc36386162c796f34 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sat, 23 Dec 2023 10:58:53 +0100 Subject: [PATCH] lib: run microtasks before ticks 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: https://github.com/nodejs/node/issues/51156 Refs: https://github.com/nodejs/node/issues/51156#issuecomment-1864656761 Refs: https://github.com/nodejs/node/pull/51114 Refs: https://github.com/nodejs/node/pull/51070 Refs: https://github.com/nodejs/node/issues/51156 PR-URL: https://github.com/nodejs/node/pull/51267 --- doc/api/cli.md | 14 +++++++ lib/internal/process/task_queues.js | 57 +++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/doc/api/cli.md b/doc/api/cli.md index 072b3b8ead55b8..6140bc112a8cfc 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -863,6 +863,20 @@ Use this flag to generate a blob that can be injected into the Node.js binary to produce a [single executable application][]. See the documentation about [this configuration][`--experimental-sea-config`] for details. + +### `--experimental-task-ordering` + + + +> Stability: 1 - Experimental + +Enable experimental task ordering. Always drain micro task queue +before running `process.nextTick` to avoid unintuitive behavior +and unexpected logical deadlocks when mixing async callback and +event API's with `Promise`, `async`/`await`` and `queueMicroTask`. + ### `--experimental-shadow-realm`