Created
December 14, 2017 22:24
-
-
Save yesil/adce6da7de0ff9c86fabb0cdb684a670 to your computer and use it in GitHub Desktop.
Promises in serial
This file contains hidden or 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 tasks = getTaskArray(); | |
return tasks.reduce((promiseChain, currentTask) => { | |
return promiseChain.then(chainResults => | |
currentTask.then(currentResult => | |
[ ...chainResults, currentResult ] | |
) | |
); | |
}, Promise.resolve([])).then(arrayOfResults => { | |
// Do something with all results | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment