-
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
[feature] Promise returning process.nextTick #19617
Comments
I think it would be helpful to know about use cases that are not already covered by |
|
@sindresorhus If that is the argument, we probably shouldn’t overload (But still, I am not sure that I ever wanted to use some kind of artificial deferral in an |
|
IIRC one could also do |
@TimothyGu I've been using async/await since it was introduced in Babel and I've never thought of doing that. It's an ok workaround, but not a nice general solution. |
Sounds like this would be better to add to the Promise implementation:
Although I'd think it would be better left to a Promise library like |
If you just want to show intent, you can do this: async function fn() {
await process.nextTick;
} |
I just realized, what I actually want is an await-friendly |
There's a much higher bar to adding things to |
Isn't this the purpose of const util = require('util');
const nextTick = util.promisify(process.nextTick);
// ...
await nextTick(); |
I consider |
@sindresorhus Would the promisified version of
I mean, you're basically asking for |
|
Are there any differences in timing, queue priority, etc between |
Well, there is: 329fc78 |
|
@timoxley All queued Strictly speaking, if we returned a promise and only resolved it in the @sindresorhus The fs/promises stuff has API and performance implications. Promisified |
I'm not talking about performance, I mean exposing promise APIs over |
I'm not just talking about performance. There's more to the promisifed I also don't believe that making the current functions be polymorphic is a great idea, which means that shipping promisifed global.setImmediateAsync = util.promisify(setImmediate);
process.nextTickAsync = (arg) => Promise.resolve(arg); I mean, that's literally the PR there... with some bike-shedding for the naming. |
What about new function with a better name and API then? |
I see absolutely zero reason to promisify or await nextTick. I see why it would be nice to have in theory but I simply do not see any use case. A bigger problem is that it would be lying, when I execute a |
Also, reading your comment @sindresorhus that is a lot more likely and makes sense (async setImmediate). We already support this through I've opened an issue about this (for setTimeout): #19426 |
It seems like discussion has exhausted itself. If anyone feels strongly, feel free to reopen. |
Worth mentioning that it is almost always better to use |
Just a quick idea I had after talking to @sindresorhus.
When
process.nextTick()
is called without a function, return a Promise:in effect:
As more of Node (possibly) moves to Promises/async-await for APIs (#15413) this makes sense I think
The text was updated successfully, but these errors were encountered: