diff options
author | Caolan McMahon <caolan@caolanmcmahon.com> | 2013-03-03 11:25:18 +0000 |
---|---|---|
committer | Caolan McMahon <caolan@caolanmcmahon.com> | 2013-03-03 11:25:18 +0000 |
commit | f4dbaf601b1fc6f9436d200ef716dc5a47870423 (patch) | |
tree | 256ad2d81f9e108a116165ab39af85afbd1a8f1b /test | |
parent | d321d633d10f2b04d25edd702f9db7614a9cff59 (diff) | |
download | async-f4dbaf601b1fc6f9436d200ef716dc5a47870423.tar.gz |
add applyEach function
Diffstat (limited to 'test')
-rwxr-xr-x | test/test-async.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/test-async.js b/test/test-async.js index 1caf1bc..5bd72bf 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -66,6 +66,66 @@ function getFunctionsObject(call_order) { }; } +exports['applyEach'] = function (test) { + test.expect(4); + var call_order = []; + var one = function (val, cb) { + test.equal(val, 5); + setTimeout(function () { + call_order.push('one'); + cb(null, 1); + }, 100); + }; + var two = function (val, cb) { + test.equal(val, 5); + setTimeout(function () { + call_order.push('two'); + cb(null, 2); + }, 50); + }; + var three = function (val, cb) { + test.equal(val, 5); + setTimeout(function () { + call_order.push('three'); + cb(null, 3); + }, 150); + }; + async.applyEach([one, two, three], 5, function (err) { + test.same(call_order, ['two', 'one', 'three']); + test.done(); + }); +}; + +exports['applyEach partial application'] = function (test) { + test.expect(4); + var call_order = []; + var one = function (val, cb) { + test.equal(val, 5); + setTimeout(function () { + call_order.push('one'); + cb(null, 1); + }, 100); + }; + var two = function (val, cb) { + test.equal(val, 5); + setTimeout(function () { + call_order.push('two'); + cb(null, 2); + }, 50); + }; + var three = function (val, cb) { + test.equal(val, 5); + setTimeout(function () { + call_order.push('three'); + cb(null, 3); + }, 150); + }; + async.applyEach([one, two, three])(5, function (err) { + test.same(call_order, ['two', 'one', 'three']); + test.done(); + }); +}; + exports['compose'] = function (test) { test.expect(4); var add2 = function (n, cb) { |