diff --git a/.gitignore b/.gitignore index 93f1361..160cf78 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules npm-debug.log +.idea +yarn.lock diff --git a/index.js b/index.js index 74af191..64e4a40 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,8 @@ 'use strict' -module.exports = function promiseWaterfall (callbacks) { +module.exports = function promiseWaterfall (callbacks, initialArgs) { // Don't assume we're running in an environment with promises return callbacks.reduce(function (accumulator, callback) { return accumulator.then(callback) - }, Promise.resolve()) + }, Promise.resolve(initialArgs)) } diff --git a/test.js b/test.js index ad186e2..692a60c 100644 --- a/test.js +++ b/test.js @@ -34,6 +34,18 @@ test('run array of promises sequentially', function (t) { }) }) +test('run array of promises sequentially with an initialization parameter', function (t) { + t.plan(1) + + return promiseWaterfall([ + addOne, + addTwo + ], 10) + .then(function (sum) { + t.equals(sum, 13) + }) +}) + test('run array consisting of zero promises', function (t) { t.plan(1)