Skip to content

Instantly share code, notes, and snippets.

@adamreisnz
Created February 15, 2016 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamreisnz/3f55d1fed7f82e286b80 to your computer and use it in GitHub Desktop.
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
'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