git ssb

16+

Dominic / patchbay



Tree: 1f66b9d5a43300423b755e4664f3b1ec5c349044

Files: 1f66b9d5a43300423b755e4664f3b1ec5c349044 / 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