-
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
Deprecate process.nextTick in favor of queueMicrotask #36870
Comments
As you suggest, |
We likely cannot ever deprecate process.nextTick, but we can start steering people towards queueMicrotask for most cases. Signed-off-by: James M Snell <[email protected]> Fixes: nodejs#36870
PR: #37484 |
The assessment @jasnell did is correct. I don't think we'll be able to remove process.nextTick(), it's everywhere. |
We likely cannot ever deprecate process.nextTick, but we can start steering people towards queueMicrotask for most cases. Signed-off-by: James M Snell <[email protected]> Fixes: nodejs#36870
Since it seems slower than nextTick. I'm not sure everyone agrees nextTick should be deprecated. We should though be more explicit about the edge cases with |
Does the "write idiomatic JavaScript, we will optimize" rule apply here? queueMicrotask being the idiomatic API. |
This comment has been minimized.
This comment has been minimized.
Likely not without it being a significant breaking change. The fact that Consider the following examples: const p = Promise.resolve();
p.then(() => {
process.nextTick(() => console.log('a'));
})
p.then(() => {
queueMicrotask(() => console.log('b'));
})
p.finally(() => {
console.log('c');
}); The order in which the items are printed here is: c, b, a. If you change the const p = Promise.resolve();
p.then(() => {
queueMicrotask(() => console.log('a'));
// process.nextTick(() => console.log('a'));
})
p.then(() => {
queueMicrotask(() => console.log('b'));
})
p.finally(() => {
console.log('c');
}); The order becomes c, a, b While the change is extremely subtle on the surface, it can cause significant problems in practice, particularly with code that's been written to expect a particular timing. That's not to say we shouldn't make that kind of change! It just means we have to be careful and understand that it could definitely break things. |
@jasnell The PR is pretty nice! Thank you for picking this up 😻 It does seem to me like @vweevers point is valid as in: use of queueMicrotask should over time should be same fast / faster. Very curious why it isnt. In any case: I agree that a change of a current API does not make sense. But do new API's need to on the "nextTick" timing? |
It's really not a matter of the performance difference between |
We likely cannot ever deprecate process.nextTick, but we can start steering people towards queueMicrotask for most cases. Signed-off-by: James M Snell <[email protected]> Fixes: #36870 PR-URL: #37484 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Robert Nagy <[email protected]>
We likely cannot ever deprecate process.nextTick, but we can start steering people towards queueMicrotask for most cases. Signed-off-by: James M Snell <[email protected]> Fixes: #36870 PR-URL: #37484 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Robert Nagy <[email protected]>
Trying to work out some things with readable-stream recently and I noticed that
queueMicrotask
seems to be sharing the same operational paradigm asprocess.nextTick
(as in: same time & style of execution). It is native to the v8 and available in browsers, has some async hooks available so I was wondering if - long term and in the spirit of cross-platform compatibility - to shift, little-by-little, fromprocess.nextTick
toqueueMicrotask
? 😅The request to deprecate may be a bit much, as
process.nextTick
is probably used everywhere and I was wondering if a soft-deprecation may be a good idea: i.e. mention thatqueueMicrotask
is the preferred way to go and that it only exists for legacy reasons? And maybe not use it for new API's?The text was updated successfully, but these errors were encountered: