diff options
author | Augusto Franzoia <ajfranzoia@gmail.com> | 2016-03-07 00:57:22 -0300 |
---|---|---|
committer | Augusto Franzoia <ajfranzoia@gmail.com> | 2016-03-07 00:57:22 -0300 |
commit | 0d87dd08374f95df0ba1449cdbb4bc5db320dee7 (patch) | |
tree | 87e1fb4e325831d55d7ce3490201ec3ef9720a24 /test | |
parent | f75579366c69940dad5d4ee0b6b7070485701481 (diff) | |
download | async-0d87dd08374f95df0ba1449cdbb4bc5db320dee7.tar.gz |
Support function timeout via async.timeout wrapper
Diffstat (limited to 'test')
-rwxr-xr-x | test/test-async.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/test-async.js b/test/test-async.js index bd103bf..b4aef6c 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -3825,3 +3825,49 @@ exports['asyncify'] = { return promises; }, {}) }; + +exports['timeout'] = function (test) { + test.expect(3); + + async.series([ + async.timeout(function asyncFn(callback) { + setTimeout(function() { + callback(null, 'I didn\'t time out'); + }, 50); + }, 200), + async.timeout(function asyncFn(callback) { + setTimeout(function() { + callback(null, 'I will time out'); + }, 300); + }, 150) + ], + function(err, results) { + test.ok(err.message === 'Callback function timed out.'); + test.ok(err.code === 'ETIMEDOUT'); + test.ok(results[0] === 'I didn\'t time out'); + test.done(); + }); +}; + +exports['timeout with parallel'] = function (test) { + test.expect(3); + + async.parallel([ + async.timeout(function asyncFn(callback) { + setTimeout(function() { + callback(null, 'I didn\'t time out'); + }, 50); + }, 200), + async.timeout(function asyncFn(callback) { + setTimeout(function() { + callback(null, 'I will time out'); + }, 300); + }, 150) + ], + function(err, results) { + test.ok(err.message === 'Callback function timed out.'); + test.ok(err.code === 'ETIMEDOUT'); + test.ok(results[0] === 'I didn\'t time out'); + test.done(); + }); +}; |