-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (28 loc) · 722 Bytes
/
index.js
File metadata and controls
33 lines (28 loc) · 722 Bytes
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
/*! run-waterfall. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
module.exports = runWaterfall
function runWaterfall (tasks, cb) {
let current = 0
let isSync = true
function done (err, args) {
function end () {
args = args ? [].concat(err, args) : [err]
if (cb) cb.apply(undefined, args)
}
if (isSync) process.nextTick(end)
else end()
}
function each (err) {
const args = Array.prototype.slice.call(arguments, 1)
if (++current >= tasks.length || err) {
done(err, args)
} else {
tasks[current].apply(undefined, [].concat(args, each))
}
}
if (tasks.length) {
tasks[0](each)
} else {
done(null)
}
isSync = false
}