test.js
1 KB
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
58
59
60
61
62
var assert = require('assert')
var parallel = require('./')
var a, b, c
parallel([
function (done) {
setTimeout(function () {
done(null, a = 0)
}, 5)
},
function (done) {
setTimeout(function () {
done(null, b = 1)
}, 10)
},
function (done) {
setTimeout(function () {
done(null, c = 2)
}, 15)
}
], function (err, results) {
assert.equal(a, 0)
assert.equal(b, 1)
assert.equal(c, 2)
assert.deepEqual(results, [0, 1, 2])
})
var d, e
parallel([
function (done) {
setTimeout(function () {
d = 1
done(new Error('message'))
}, 5)
},
function (done) {
setTimeout(function () {
e = 2
done()
}, 10)
}
], function (err) {
assert.equal(err.message, 'message')
assert.equal(d, 1)
assert.equal(e, undefined)
})
var context = 'hello'
parallel([function (done) {
assert.equal(this, context)
}], context)
var f
parallel([function (done) {
f = true
done()
}])
process.nextTick(function () {
assert.equal(f, true)
})