diff options
author | Graeme Yeates <yeatesgraeme@gmail.com> | 2015-07-03 16:49:59 -0400 |
---|---|---|
committer | Graeme Yeates <yeatesgraeme@gmail.com> | 2015-07-03 19:48:43 -0400 |
commit | e3f6537560e34cd8748214dc762bf18189e9fb54 (patch) | |
tree | 0e9af57cb715e8c7b3890459f8731d47b197a565 | |
parent | cd4d65dd60d0b2e2eae8fc16d5995ac35831a87d (diff) | |
download | async-e3f6537560e34cd8748214dc762bf18189e9fb54.tar.gz |
Simplify nextTick and setImmediate definitions
-rw-r--r-- | lib/async.js | 42 |
1 files changed, 13 insertions, 29 deletions
diff --git a/lib/async.js b/lib/async.js index 819b426..f6ef7c1 100644 --- a/lib/async.js +++ b/lib/async.js @@ -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) { |