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
49
50
51
52
53
54
55
56
57
|
var async = require('../lib');
var expect = require('chai').expect;
var assert = require('assert');
describe('concat', function() {
it('concat', function(done) {
var call_order = [];
var iteratee = function (x, cb) {
setTimeout(function(){
call_order.push(x);
var r = [];
while (x > 0) {
r.push(x);
x--;
}
cb(null, r);
}, x*25);
};
async.concat([1,3,2], iteratee, function(err, results){
expect(results).to.eql([1,2,1,3,2,1]);
expect(call_order).to.eql([1,2,3]);
assert(err === null, err + " passed instead of 'null'");
done();
});
});
it('concat error', function(done) {
var iteratee = function (x, cb) {
cb(new Error('test error'));
};
async.concat([1,2,3], iteratee, function(err){
assert(err);
done();
});
});
it('concatSeries', function(done) {
var call_order = [];
var iteratee = function (x, cb) {
setTimeout(function(){
call_order.push(x);
var r = [];
while (x > 0) {
r.push(x);
x--;
}
cb(null, r);
}, x*25);
};
async.concatSeries([1,3,2], iteratee, function(err, results){
expect(results).to.eql([1,3,2,1,2,1]);
expect(call_order).to.eql([1,3,2]);
assert(err === null, err + " passed instead of 'null'");
done();
});
});
});
|