run-series
Advanced tools
Comparing version 0.2.0 to 0.3.0
45
index.js
@@ -1,18 +0,15 @@ | ||
module.exports = function (tasks, cb) { | ||
module.exports = series | ||
module.exports.waterfall = waterfall | ||
function series (tasks, cb) { | ||
var current = 0 | ||
var results = [] | ||
cb = cb || function () {} | ||
function done (err, result) { | ||
if (err) { | ||
cb && cb(err, results) | ||
cb = null | ||
return | ||
} | ||
if (err) return cb(err, results) | ||
results.push(result) | ||
current += 1 | ||
if (current >= tasks.length) { | ||
cb && cb(null, results) | ||
cb = null | ||
if (++current >= tasks.length) { | ||
cb(null, results) | ||
} else { | ||
@@ -26,5 +23,27 @@ tasks[current](done) | ||
} else { | ||
cb && cb(null, []) | ||
cb = null | ||
cb(null, []) | ||
} | ||
} | ||
function waterfall (tasks, cb) { | ||
var current = 0 | ||
cb = cb || function () {} | ||
function done (err) { | ||
var args = Array.prototype.slice.call(arguments, 1) | ||
if (err) return cb(err, args) | ||
if (++current >= tasks.length) { | ||
cb.apply(undefined, [null].concat(args)) | ||
} else { | ||
tasks[current].apply(undefined, args.concat(done)) | ||
} | ||
} | ||
if (tasks.length) { | ||
tasks[current](done) | ||
} else { | ||
cb(null, []) | ||
} | ||
} | ||
{ | ||
"name": "run-series", | ||
"description": "Run an array of functions in series", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Feross Aboukhadijeh", |
@@ -19,3 +19,3 @@ # run-series [![travis](https://img.shields.io/travis/feross/run-series.svg)](https://travis-ci.org/feross/run-series) [![npm](https://img.shields.io/npm/v/run-series.svg)](https://npmjs.org/package/run-series) [![gittip](https://img.shields.io/gittip/feross.svg)](https://www.gittip.com/feross/) | ||
function has completed. If any functions in the series pass an error to its callback, no | ||
more functions are run, and 1callback1 is immediately called with the value of the error. | ||
more functions are run, and `callback` is immediately called with the value of the error. | ||
Otherwise, `callback` receives an array of results when `tasks` have completed. | ||
@@ -22,0 +22,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98715
11
172