git ssb

0+

dangerousbeans / dangerous_patchbay



forked from Dominic / patchbay

Tree: 74fe7cba24a1be16ab96edeb828f80c1740bef44

Files: 74fe7cba24a1be16ab96edeb828f80c1740bef44 / plugs.js

939 bytesRaw
1exports.first = function first(plug) {
2 return function () {
3 var args = [].slice.call(arguments)
4 for(var i = 0; i < plug.length; i++) {
5 var val = plug[i].apply(null, args)
6 if(val) return val
7 }
8 }
9}
10
11exports.map = function (plug) {
12 return function () {
13 var args = [].slice.call(arguments)
14 return plug.map(function (fn) {
15 if(fn) return fn.apply(null, args)
16 }).filter(Boolean)
17 }
18}
19
20exports.asyncConcat = function (plug) {
21 return function () {
22 var args = [].slice.call(arguments)
23 var cb = args.pop()
24 var allResults = []
25 var waiting = plug.length
26 plug.forEach(function (fn) {
27 if (!fn) return next()
28 fn.apply(null, args.concat(next))
29 })
30 function next(err, results) {
31 if (err) {
32 waiting = 0
33 return cb(err)
34 }
35 if (results) allResults = allResults.concat(results)
36 if (--waiting === 0) cb(null, allResults)
37 }
38 }
39}
40
41

Built with git-ssb-web