/
test.js
48 lines (39 loc) · 849 Bytes
/
test.js
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 doWhile = require('./');
exports['the-test'] = function (test) {
var a = [], x = 0;
doWhile(function (next) {
a.push(x++);
return next(x < 4);
}, function () {
test.deepEqual(a, [0,1,2,3]);
test.done();
});
};
exports['test-concurrency'] = function (test) {
var a = [500, 400, 300, 200, 100, 0];
var b = [];
doWhile(function (next) {
var x = a.shift();
setTimeout(function () {
b.push(x);
next(!!x);
}, x);
}, function () {
test.deepEqual(b, [0, 100, 200, 300, 400, 500]);
test.done();
}, 6);
}
exports['test-concurrency-2'] = function (test) {
var a = [500, 400, 300, 200, 100, 0];
var b = [];
doWhile(function (next) {
var x = a.shift();
setTimeout(function () {
b.push(x);
next(!!x);
}, x);
}, function () {
test.deepEqual(b, [400, 500, 200, 300, 0, 100]);
test.done();
}, 2);
}