UNPKG

rocky

Version:

Full-featured, middleware-oriented, hackable HTTP and WebSocket proxy

22 lines (15 loc) 410 B
module.exports = function eachSeries (arr, iterator, cb) { cb = cb || noop if (!Array.isArray(arr) || !arr.length) return cb() const stack = arr.slice() const length = iterator.length function next (err) { if (err) return cb(err) const job = stack.shift() if (!job) return cb() if (length > 1) iterator(job, next) else next(iterator(job)) } next() } function noop () {}