1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
var async = require('../lib');
var expect = require('chai').expect;
describe('timeout', function () {
it('timeout with series', function(done){
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) {
expect(err.message).to.equal('Callback function timed out.');
expect(err.code).to.equal('ETIMEDOUT');
expect(results[0]).to.equal('I didn\'t time out');
done();
});
});
it('timeout with parallel', function(done){
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) {
expect(err.message).to.equal('Callback function timed out.');
expect(err.code).to.equal('ETIMEDOUT');
expect(results[0]).to.equal('I didn\'t time out');
done();
});
});
});
|