process: make process.nextTick() awaitable#38393
process: make process.nextTick() awaitable#38393XadillaX wants to merge 2 commits intonodejs:mainfrom
process.nextTick() awaitable#38393Conversation
lib/internal/process/task_queues.js
Outdated
| let promise; | ||
|
|
||
| if (!arguments.length) { | ||
| const defered = createDeferredPromise(); |
There was a problem hiding this comment.
| const defered = createDeferredPromise(); | |
| const deferred = createDeferredPromise(); |
lib/internal/process/task_queues.js
Outdated
| const defered = createDeferredPromise(); | ||
| promise = defered.promise; | ||
| const { resolve } = defered; | ||
| callback = nextTickDefaultCallback.bind(undefined, resolve); |
There was a problem hiding this comment.
I think this could be simplified without the destructuring assignment above this line along with:
| callback = nextTickDefaultCallback.bind(undefined, resolve); | |
| callback = nextTickDefaultCallback.bind(undefined, deferred.resolve); |
devsnek
left a comment
There was a problem hiding this comment.
I don't think this should exist, it's basically "run at the end of the microtask queue after the next tick", which is not an idiom anyone should be reaching for.
It just for So: const deferred = createDeferredPromise();
setTimeout(() => { derferred.resolve; }, 0);
await deferred.promise;
// .. do something in next (or next next ...) tickmay be OK too. |
|
What use case would be solved by this that cannot work with import { setImmediate } from 'timers/promises';
await setImmediate() |
I mean just like |
|
This is similar to |
benjamingr
left a comment
There was a problem hiding this comment.
I'm also -1, if you want a version of proces.nextTick that returns a Promise you can just await null or await Promise.resolve().
If anything ideally we'll deprecate process.nextTick in favour of the web standard queueMicrotask
Note that
Their naming is pretty confusing. |
jasnell
left a comment
There was a problem hiding this comment.
I'm generally -1 on this. There are already a number of ways of doing similar deferals...
await Promise.resolve();
// or
await new Promise((resolve) => process.nextTick(resolve));
// or, with slightly different timing semantics...
const { setTimeout } = require('timers/promises');
await setTimeout();Let's leave process.nextTick() unchanged. We don't need Promise APIs for everything.
|
Yep. Making nextTick awaitable just makes things even weirder. |
|
I am -1 as well..I think this would just make things even more complex for our users, with no obvious gains |
|
As just an opinion from userland, a general -1 to bloating up and adding unnecessary complexity for minimal gain and usage. In terms of performance, this PR introduces additional quaint checks that hog the EL and you can always use any of the aforementioned solutions for some specialised use cases. Copying in @tbnritzdoge as well who is also familiar with async overhead. |
|
Think it's likely safe to close this one at this point ;-) |
For code changes:
make -j4 test(UNIX), orvcbuild test(Windows) passes.