Skip to content

Commit

Permalink
guard against setImmediate mocking. Fixes #609 #611
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Early committed May 20, 2015
1 parent 29e7141 commit e417af6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,18 @@
//// exported async module functions ////

//// nextTick implementation with browser-compatible fallback ////

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

if (typeof process === 'undefined' || !(process.nextTick)) {
if (typeof setImmediate === 'function') {
if (_setImmediate) {
async.nextTick = function (fn) {
// not a direct alias for IE10 compatibility
setImmediate(fn);
_setImmediate(fn);
};
async.setImmediate = async.nextTick;
}
Expand All @@ -129,10 +136,10 @@
}
else {
async.nextTick = process.nextTick;
if (typeof setImmediate !== 'undefined') {
if (_setImmediate) {
async.setImmediate = function (fn) {
// not a direct alias for IE10 compatibility
setImmediate(fn);
_setImmediate(fn);
};
}
else {
Expand Down

0 comments on commit e417af6

Please sign in to comment.