Created
February 15, 2016 01:40
-
-
Save adamreisnz/3f55d1fed7f82e286b80 to your computer and use it in GitHub Desktop.
Run an array of promises in series, failing when one of them fails and not running the rest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = function waterfall(promises) { | |
return promises.reduce((previousPromise, promise) => { | |
return previousPromise.then(() => { | |
return promise(); | |
}); | |
}, Promise.resolve()); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment