Skip to content

Commit

Permalink
Simplify nextTick and setImmediate definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
megawac committed Jul 3, 2015
1 parent f0fe432 commit 7f3c04f
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,38 +188,22 @@
//// nextTick implementation with browser-compatible fallback ////

// capture the global reference to guard against fakeTimer mocks
var _setImmediate;
if (typeof setImmediate === 'function') {
_setImmediate = setImmediate;
}
var _setImmediate = typeof setImmediate === 'function' && setImmediate;

if (typeof process === 'undefined' || !(process.nextTick)) {
if (_setImmediate) {
async.nextTick = function (fn) {
// not a direct alias for IE10 compatibility
_setImmediate(fn);
};
async.setImmediate = async.nextTick;
}
else {
async.nextTick = function (fn) {
setTimeout(fn, 0);
};
async.setImmediate = async.nextTick;
}
}
else {
var _delay = _setImmediate ? function(fn) {
// not a direct alias for IE10 compatibility
_setImmediate(fn);
} : function(fn) {
setTimeout(fn, 0);
};

if (typeof process === 'object' && typeof process.nextTick === 'function') {
async.nextTick = process.nextTick;
if (_setImmediate) {
async.setImmediate = function (fn) {
// not a direct alias for IE10 compatibility
_setImmediate(fn);
};
}
else {
async.setImmediate = async.nextTick;
}
} else {
async.nextTick = _delay;
}
async.setImmediate = _setImmediate ? _delay : async.nextTick;


async.forEach =
async.each = function (arr, iterator, callback) {
Expand Down

0 comments on commit 7f3c04f

Please sign in to comment.