Browse Source

timers: setImmediate process full queue each turn

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 #5798
v0.11.4-release
Ben Noordhuis 12 years ago
committed by isaacs
parent
commit
fa46483fe2
  1. 22
      lib/timers.js

22
lib/timers.js

@ -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;
}
}

Loading…
Cancel
Save