Skip to content

Commit

Permalink
timers: setImmediate process full queue each turn
Browse files Browse the repository at this point in the history
Previously only one cb per turn of the event loop was processed at a
time, which is not exactly what is meant by immediate

fixes nodejs#5798
  • Loading branch information
bnoordhuis authored and isaacs committed Jul 12, 2013
1 parent c679ac8 commit fa46483
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,18 +313,24 @@ L.init(immediateQueue);


function processImmediate() {
var immediate = L.shift(immediateQueue);
var queue = immediateQueue;

if (L.isEmpty(immediateQueue)) {
process._needImmediateCallback = false;
}

if (immediate._onImmediate) {
if (immediate.domain) immediate.domain.enter();
immediateQueue = {};
L.init(immediateQueue);

while (L.isEmpty(queue) === false) {
var immediate = L.shift(queue);
var domain = immediate.domain;
if (domain) domain.enter();
immediate._onImmediate();
if (domain) domain.exit();
}

if (immediate.domain) immediate.domain.exit();
// Only round-trip to C++ land if we have to. Calling clearImmediate() on an
// immediate that's in |queue| is okay. Worst case is we make a superfluous
// call to NeedImmediateCallbackSetter().
if (L.isEmpty(immediateQueue)) {
process._needImmediateCallback = false;
}
}

Expand Down

0 comments on commit fa46483

Please sign in to comment.