-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Make setTimeout and setImmediate timers run consecutively #8460
Comments
What are these? Just Immediates or timers scheduled in Immediates? Immediates should fire after I/O before Timeouts, right? |
Immediates.
That's right, the actual callbacks are made from a check handle. I realize what tripped me up: we call The order of events is approximately: start tick -> timeouts -> I/O -> immediates -> close callbacks -> timeouts again -> end tick. |
Should this stay open? If so, @Fishrock123: Are you likely to get to this soon? If not, should we unassign you and/or add |
The |
9e08695 should have fixed the ordering, yes. The issue of timer callbacks and immediate callbacks getting interleaved with other callbacks still exists. |
Is this taken? I would like to work on this one. |
Hi @j0t3x, unfortunately I don't know if there's a clear direction here even... It's a strong possibility that there might be code out there relying on immediates running after I/O. (For reference http://docs.libuv.org/en/v1.x/design.html) Also, the fact that setImmediate will run within the same iteration of the loop for everything but close callbacks is IMO a good thing. |
|
I've removed the help-wanted label. I'm not sure anyone truly knows what's best here. I would be in favour of sticking with the current behaviour but of course there is some weirdness associated with it. If we hang them off the timer handle then scheduling them seems to become a bit more problematic — I'm not 100% certain how @bnoordhuis envisions that working, but he also knows libuv a lot better than I so I trust that it's possible in an elegant manner. |
How so? |
As far as I can tell they would need to be timers scheduled for 1ms, right? (Scheduling for 0 while in the timer handling process seems to cause those timers to fire again before running the loop again.) Or is there some other way to hang them off the timer? As I said, only mildly knowledgeable about libuv. |
I'm not sure part of this issue exists anymore, since we no longer use |
Actually, I'm not sure there is an issue at all anymore. The definition of
The OP mentions that close handles can fire before immediates after timeouts, but the code of The uv loop executes callbacks in the following order each loop:
|
This should just be closed at this point. There's nothing actionable here, at least nothing that anyone is realistically willing to do. |
Continuing from libuv/libuv#1035 (comment):
Node.js uses a uv_idle_t handle to implement
setImmediate()
timers but I think it could - and should - hang them off the bigsetTimeout()
timer.Right now you have this weird situation where:
a) setTimeout timers run,
b) some other callbacks run (mostly close callbacks), then
c) setImmediate timers run.
The text was updated successfully, but these errors were encountered: