-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
run microtasks before ticks #51267
run microtasks before ticks #51267
Conversation
c8b5df2
to
66904c9
Compare
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 (comment) Refs: nodejs#51070 Refs: nodejs#51156 PR-URL: nodejs#51267
66904c9
to
d95c4cb
Compare
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
This comment was marked as resolved.
This comment was marked as resolved.
If think that IF we do this, which is something we need to very carefully consider given the very real chance of breakage, we should include an escape hatch in the form of a command-line argument that restores the original ordering. We can eventually deprecate that flag once the ecosystem has had a while to make the transition.
|
d95c4cb
to
17de9ba
Compare
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
17de9ba
to
1a5a03b
Compare
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
What about having it as an opt-in for now? |
1a5a03b
to
6fedd50
Compare
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
6fedd50
to
9df2edf
Compare
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
It might be difficult or impossible to have this by default but I still think we need to have the possibility to opt-in as this is the only way to get "correct" behavior. |
9df2edf
to
c505bc5
Compare
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer if this super-hot function would not get a few more ifs. I think you could duplicate the implementation and only change the export.
This pattern would also allow us for more experimentation.
c505bc5
to
440ff33
Compare
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
440ff33
to
d32a6ea
Compare
0e15cc6
to
ce47a8d
Compare
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
ce47a8d
to
0d9b9ca
Compare
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Please note that this is necessary as queueMicrotask is not sufficient to replace the current nextTick due to its re-entrance behavior. |
@mcollina I can't get this to work without a function wrapper due to the following lint rule: node:internal/options:20
({ options: optionsMap } = getCLIOptions());
^
Error: Should not query options before bootstrapping is done
at getCLIOptionsFromBinding (node:internal/options:20:32)
at getOptionValue (node:internal/options:45:19)
at setupTaskQueue (node:internal/process/task_queues:210:34)
at node:internal/bootstrap/node:306:38 Any suggestions? Or who might have some idea? |
@joyeecheung You are the one that added the rule I believe? |
lib/internal/process/task_queues.js
Outdated
callback(); | ||
} else { | ||
const args = tock.args; | ||
switch (args.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this actually faster?
a88c594
to
3a1c141
Compare
3a1c141
to
34b7227
Compare
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
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
34b7227
to
da76346
Compare
|
||
> Stability: 1 - Experimental | ||
|
||
Enable experimental task ordering. Always drain micro task queue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enable experimental task ordering. Always drain micro task queue | |
Enable experimental task ordering. Always drain Microtasks queue |
It would also be useful to link to a doc like https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide#microtasks here.
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you provide some examples? Without examples I doubt how many users would be able to recognize whether this can be useful for them and pick up this option.
Also note that we have a section in process.md saying..
every time the "next tick queue" is drained, the microtask queue
is drained immediately after.
I think that should be updated to mention this option.
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.
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 withPromise
,async
/await
andqueueMicroTask
.Refs: #51156
Refs: #51156
Refs: #51114 (comment)
Refs: #51070
Refs: #51156