utils: improve nextTick.

This commit is contained in:
Christopher Jeffrey 2014-06-06 16:22:47 -05:00
parent eadb7a50c7
commit 7b928f079c

View File

@ -372,9 +372,18 @@ utils.isEqual = function isEqual(a, b) {
return true;
};
// TODO(indutny): use process.nextTick in node.js
utils.nextTick = function nextTick(fn) {
setTimeout(fn, 0);
if (typeof setImmediate === 'function') {
setImmediate(fn);
return;
}
if (typeof process === 'object' && process.nextTick) {
process.nextTick(fn);
return;
}
setTimeout(fn, 1);
};
function RequestCache() {