Skip to content

Commit 7f3c04f

Browse files
committed
Simplify nextTick and setImmediate definitions
1 parent f0fe432 commit 7f3c04f

File tree

1 file changed

+13
-29
lines changed

1 file changed

+13
-29
lines changed

lib/async.js

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -188,38 +188,22 @@
188188
//// nextTick implementation with browser-compatible fallback ////
189189

190190
// capture the global reference to guard against fakeTimer mocks
191-
var _setImmediate;
192-
if (typeof setImmediate === 'function') {
193-
_setImmediate = setImmediate;
194-
}
191+
var _setImmediate = typeof setImmediate === 'function' && setImmediate;
195192

196-
if (typeof process === 'undefined' || !(process.nextTick)) {
197-
if (_setImmediate) {
198-
async.nextTick = function (fn) {
199-
// not a direct alias for IE10 compatibility
200-
_setImmediate(fn);
201-
};
202-
async.setImmediate = async.nextTick;
203-
}
204-
else {
205-
async.nextTick = function (fn) {
206-
setTimeout(fn, 0);
207-
};
208-
async.setImmediate = async.nextTick;
209-
}
210-
}
211-
else {
193+
var _delay = _setImmediate ? function(fn) {
194+
// not a direct alias for IE10 compatibility
195+
_setImmediate(fn);
196+
} : function(fn) {
197+
setTimeout(fn, 0);
198+
};
199+
200+
if (typeof process === 'object' && typeof process.nextTick === 'function') {
212201
async.nextTick = process.nextTick;
213-
if (_setImmediate) {
214-
async.setImmediate = function (fn) {
215-
// not a direct alias for IE10 compatibility
216-
_setImmediate(fn);
217-
};
218-
}
219-
else {
220-
async.setImmediate = async.nextTick;
221-
}
202+
} else {
203+
async.nextTick = _delay;
222204
}
205+
async.setImmediate = _setImmediate ? _delay : async.nextTick;
206+
223207

224208
async.forEach =
225209
async.each = function (arr, iterator, callback) {

0 commit comments

Comments
 (0)