diff options
author | Alexander Early <alexander.early@gmail.com> | 2017-04-03 23:46:20 -0700 |
---|---|---|
committer | Alexander Early <alexander.early@gmail.com> | 2017-04-03 23:46:20 -0700 |
commit | 53019a85063576c3aa7e48410d5f8018337f348e (patch) | |
tree | fd0672a815476acfacbf16b441aba918b8f49ffc /lib/waterfall.js | |
parent | dddb9f50a079580f938e69f1ba9d32927a08301c (diff) | |
download | async-53019a85063576c3aa7e48410d5f8018337f348e.tar.gz |
simplify waterfall, commit built files
Diffstat (limited to 'lib/waterfall.js')
-rw-r--r-- | lib/waterfall.js | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/lib/waterfall.js b/lib/waterfall.js index d5245c3..e4c033a 100644 --- a/lib/waterfall.js +++ b/lib/waterfall.js @@ -68,25 +68,23 @@ export default function(tasks, callback) { if (!isArray(tasks)) return callback(new Error('First argument to waterfall must be an array of functions')); if (!tasks.length) return callback(); var taskIndex = 0; + var args = []; - function nextTask(args) { - if (taskIndex === tasks.length) { - return callback.apply(null, [null].concat(args)); - } - - var taskCallback = onlyOnce(function(err/*, cbArgs...*/) { - var cbArgs = slice(arguments, 1); - if (err) { - return callback.apply(null, [err].concat(cbArgs)); - } - nextTask(cbArgs); - }); - + function nextTask() { + var task = wrapAsync(tasks[taskIndex++]); + var taskCallback = onlyOnce(next); args.push(taskCallback); - var task = wrapAsync(tasks[taskIndex++]); task.apply(null, args); } - nextTask([]); + function next(err/*, ...args*/) { + if (err || taskIndex === tasks.length) { + return callback.apply(null, arguments); + } + args = slice(arguments, 1); + nextTask(); + } + + nextTask(); } |