-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pass extra args to setImmediate/nextTick. Fixes #940
- Loading branch information
Showing
5 changed files
with
78 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
'use strict'; | ||
import rest from 'lodash/rest'; | ||
|
||
var _setImmediate = typeof setImmediate === 'function' && setImmediate; | ||
|
||
var _delay; | ||
var _defer; | ||
if (_setImmediate) { | ||
_delay = function(fn) { | ||
// not a direct alias for IE10 compatibility | ||
_setImmediate(fn); | ||
}; | ||
_defer = _setImmediate; | ||
} else if (typeof process === 'object' && typeof process.nextTick === 'function') { | ||
_delay = process.nextTick; | ||
_defer = process.nextTick; | ||
} else { | ||
_delay = function(fn) { | ||
_defer = function(fn) { | ||
setTimeout(fn, 0); | ||
}; | ||
} | ||
|
||
export default _delay; | ||
export default rest(function (fn, args) { | ||
_defer(function () { | ||
fn.apply(null, args); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var async = require('../lib'); | ||
var expect = require('chai').expect; | ||
|
||
describe("nextTick", function () { | ||
|
||
it('basics', function(done){ | ||
var call_order = []; | ||
async.nextTick(function(){call_order.push('two');}); | ||
call_order.push('one'); | ||
setTimeout(function(){ | ||
expect(call_order).to.eql(['one','two']); | ||
done(); | ||
}, 50); | ||
}); | ||
|
||
it('nextTick in the browser', function(done){ | ||
if (!process.browser) { | ||
// skip this test in node | ||
return done(); | ||
} | ||
|
||
var call_order = []; | ||
async.nextTick(function(){call_order.push('two');}); | ||
|
||
call_order.push('one'); | ||
setTimeout(function(){ | ||
expect(call_order).to.eql(['one','two']); | ||
done(); | ||
}, 50); | ||
}); | ||
|
||
it("extra args", function (done) { | ||
async.nextTick(function (a, b, c) { | ||
expect([a, b, c]).to.eql([1, 2, 3]); | ||
done(); | ||
}, 1, 2, 3); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var async = require('../lib'); | ||
var expect = require('chai').expect; | ||
|
||
describe("setImmediate", function () { | ||
|
||
it('basics', function(done){ | ||
var call_order = []; | ||
async.setImmediate(function(){call_order.push('two');}); | ||
call_order.push('one'); | ||
|
||
setTimeout(function(){ | ||
expect(call_order).to.eql(['one','two']); | ||
done(); | ||
}, 25); | ||
}); | ||
|
||
it("extra args", function (done) { | ||
async.setImmediate(function (a, b, c) { | ||
expect([a, b, c]).to.eql([1, 2, 3]); | ||
done(); | ||
}, 1, 2, 3); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters