-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Promises wiggle their way between nextTick
and setImmediate
#2736
Comments
enter the "micro task queue" .. there was an interesting discussion at the last TSC meeting about possibly using the V8 micro task queue to implement the nextTick (I think), perhaps @trevnorris or @domenic can chime in on this one |
@rvagg -- I'm not certain, but I think this would be related to |
This is correct behaviour, bluebird does the wrong thing |
@vkurchatkin - well bluebird can't do the correct thing, can it? I don't know of any exposed API to get a callback to fire between And given that, I don't understand why some native code to fitting into a "magical" timing spot is correct behavior. But even if it is, can you clarify when the Promise callbacks run? Is it pre or post IO? |
@zyklus From the docs (for
I would not recommend relying on the exact execution order of non-chained events. The order of
Amd everything looks ok from that side. |
@ChALkeR -- Yes, I realize that and it's not what I'm concerned about. As I said initially, I already changed the code in question. My question is about whether promises fire before or after IO. |
IMO there is no "correct" thing, it's just implementation details that can change.
For now, |
There is no correct answer in the ES spec. It is up to the embedding environment. For the web, the intent is for the PromiseJob queue to be subsumed by the microtask queue, pre-IO. Node should choose the same. |
Native promise handlers are executed on a microtask queue which is roughly the same as |
BTW, I answered your question when you asked it in Stack Overflow with the same answer provided here. |
@domenic mind elaborating on "the intent is for the PromiseJob queue to be subsumed by the microtask queue, pre-IO"? May just be the jet-lag, but not following. |
@trevnorris what ES calls the PromiseJob queue can be implemented by any embedder or engine in any way, as long as they follow the very few restrictions in the ES spec. (Basically, it must be ordered.) The intent is for platforms that have a microtask queue (like HTML, or Node.js, or V8) to use that as the PromiseJob queue, which will fulfill all the requirements, and will also cause promise jobs to happen pre-IO, since that is when microtasks happen. |
@domenic It's the pre-IO thing that's tripping me up. I can't visualize how that would fit into the event loop. |
This doesn't seem right to me, but feel free to close if it is. Promises somehow always get in between
nextTick
andsetImmediate
. This was causing a weird timing bug for me when I switched some code from Bluebird to native promises:Native yields:
Bluebird yields:
The text was updated successfully, but these errors were encountered: