Skip to content

Commit

Permalink
Merge pull request #10 from xuxihai123/master
Browse files Browse the repository at this point in the history
Support an initialization parameter
  • Loading branch information
notjrbauer committed Oct 26, 2018
2 parents ae6e469 + 57fb8df commit 1a7197f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,2 +1,4 @@
node_modules
npm-debug.log
.idea
yarn.lock
4 changes: 2 additions & 2 deletions 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))
}
12 changes: 12 additions & 0 deletions test.js
Expand Up @@ -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)

Expand Down

0 comments on commit 1a7197f

Please sign in to comment.