-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.js
executable file
·73 lines (57 loc) · 1.35 KB
/
index.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Load modules
// Declare internals
var internals = {};
exports.serial = function (array, method, callback) {
var il = array.length
if (!il) {
callback();
}
else {
var i = 0;
var iterate = function () {
var done = function (err) {
if (err) {
callback(err);
}
else {
i += 1;
if (i < il) {
iterate();
}
else {
callback();
}
}
};
method(array[i], done);
};
iterate();
}
};
exports.parallel = function (array, method, callback) {
var il = array.length
if (!il) {
callback();
}
else {
var count = 0;
var errored = false;
var done = function (err) {
if (!errored) {
if (err) {
errored = true;
callback(err);
}
else {
count += 1;
if (count === array.length) {
callback();
}
}
}
};
for (var i = 0; i < il; ++i) {
method(array[i], done);
}
}
};