-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (37 loc) · 931 Bytes
/
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
"use strict"
module.exports= {
parallel: function parallel(){
var results = [];
var counter = 0;
var shouldReturn = false;
var args = Array.prototype.slice.call(arguments);
var fns = args.slice(0, args.length-1);
var final = args[args.length-1];
fns.map(function(fn, index) {
fn(function(error, result) {
if(shouldReturn)
return;
if (error){
shouldReturn = true;
return final(error);
}
results[index] = result;
counter++;
if (counter === fns.length)
return final(undefined, results);
});
});
},
series: function series(fns, final, result){
if(fns.length){
var fn = fns.shift();
return fn(result, function(err, res){
if(err)
return final(err, result);
series(fns, final, res);
});
}else{
return final(null, result);
}
}
}