Last active
June 23, 2017 03:41
-
-
Save chriswrightdesign/62524e5c6b97598bf4eb15826dee760d to your computer and use it in GitHub Desktop.
Promise sequence or 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
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