Created
October 3, 2016 08:45
-
-
Save rubystream/b0c2973fddb1af2977f18330a63440b4 to your computer and use it in GitHub Desktop.
Promise waterfall
This file contains 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
// objectsToProcess - array of objects to process | |
// asyncFunction - asynct function that take objectsToProcess item as argument and return a promise | |
var promise = objectsToProcess.reduce((accumulator , item) => { | |
return accumulator.then(asyncFunction(item)); | |
}, Promise.resolve()); | |
promise | |
.then(console.log) | |
.catch(console.log); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment