diff --git a/lib/executor.js b/lib/executor.js index f06f1ab..a555bd3 100644 --- a/lib/executor.js +++ b/lib/executor.js @@ -22,7 +22,11 @@ function Executor () { // Always tell the queue task is complete. Execute callback if any was given. if (typeof lastArg === 'function') { callback = function () { - process.nextTick(cb); + if (typeof setImmediate === 'function') { + setImmediate(cb); + } else { + process.nextTick(cb); + } lastArg.apply(null, arguments); }; diff --git a/test/executor.test.js b/test/executor.test.js index 17b907e..0c911bd 100644 --- a/test/executor.test.js +++ b/test/executor.test.js @@ -74,7 +74,22 @@ function testRightOrder (d, done) { }); } - + + +// Note: The following test does not have any assertion because it +// is meant to address the deprecation warning: +// (node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral. +// see +var testEventLoopStarvation = function(d, done){ + var times = 1001; + var i = 0; + while ( i