UNPKG

770 BJavaScriptView Raw
1var pull = require('pull-stream')
2
3function all(ary, abort, cb) {
4 var n = ary.length
5 ary.forEach(function (f) {
6 if(f) f(abort, next)
7 else next()
8 })
9
10 function next() {
11 if(--n) return
12 cb(abort)
13 }
14 if(!n) next()
15}
16
17module.exports = pull.Source(function (streams) {
18
19 return function (abort, cb) {
20 ;(function next () {
21 if(abort)
22 all(streams, abort, cb)
23 else if(!streams.length)
24 cb(true)
25 else if(!streams[0])
26 streams.shift(), next()
27 else
28 streams[0](null, function (err, data) {
29 if(err) {
30 streams.shift()
31 if(err !== true)
32 abort = err
33 next()
34 }
35 else
36 cb(null, data)
37 })
38 })()
39 }
40})