Skip to content

Instantly share code, notes, and snippets.

@Azerothian
Created August 3, 2016 02:36
Show Gist options
  • Save Azerothian/8bf3d52d89f442cb5a04edc263d281d4 to your computer and use it in GitHub Desktop.
Save Azerothian/8bf3d52d89f442cb5a04edc263d281d4 to your computer and use it in GitHub Desktop.
function waterfall(arr) {
return arr.reduce((promise, func) => {
return promise.then(func);
}, Promise.resolve());
}
//
// function waterfall(arr) {
// log.info("have we hit yet");
// if (arr.length === 0) {
// log.info("hit the ground");
// return Promise.resolve();
// }
// return Promise.resolve()
// .then(arr.pop())
// .then(() => {
// log.info("falling");
// return waterfall(arr);
// }, (err) => {
// log.info("water fall error occurred", err);
// if (err.stack) {
// log.info("waterfall error stack", err.stack);
// }
// return Promise.reject(err);
// });
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment