Skip to content

Instantly share code, notes, and snippets.

@chriswrightdesign
Last active June 23, 2017 03:41
Show Gist options
  • Save chriswrightdesign/62524e5c6b97598bf4eb15826dee760d to your computer and use it in GitHub Desktop.
Save chriswrightdesign/62524e5c6b97598bf4eb15826dee760d to your computer and use it in GitHub Desktop.
Promise sequence or waterfall
const first = () => Promise.resolve('this');
const second = res => Promise.resolve(`${res} is`);
const third = res => Promise.resolve(`${res} a sequence`);
const somePromises = [
first,
second,
third
];
// Execute a list of Promise return functions in series
const promiseSequence = promiseList =>
promiseList.reduce((acc, curr) => acc.then(curr), Promise.resolve());
promiseSequence(somePromises).then(res => console.log("yep:", res));
// result: yep: this is a sequence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment