1module.exports = chain 2var bindActor = require("./bind-actor.js") 3chain.first = {} ; chain.last = {} 4function chain (things, cb) { 5 var res = [] 6 ;(function LOOP (i, len) { 7 if (i >= len) return cb(null,res) 8 if (Array.isArray(things[i])) 9 things[i] = bindActor.apply(null, 10 things[i].map(function(i){ 11 return (i===chain.first) ? res[0] 12 : (i===chain.last) 13 ? res[res.length - 1] : i })) 14 if (!things[i]) return LOOP(i + 1, len) 15 things[i](function (er, data) { 16 if (er) return cb(er, res) 17 if (data !== undefined) res = res.concat(data) 18 LOOP(i + 1, len) 19 }) 20 })(0, things.length) } 21