Skip to content

Instantly share code, notes, and snippets.

@rubystream
Created October 3, 2016 08:45
Show Gist options
  • Save rubystream/b0c2973fddb1af2977f18330a63440b4 to your computer and use it in GitHub Desktop.
Save rubystream/b0c2973fddb1af2977f18330a63440b4 to your computer and use it in GitHub Desktop.
Promise waterfall
// 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