Created
October 3, 2017 21:53
-
-
Save barvian/d0004b9404f0ea455c7f50bcf58f4f43 to your computer and use it in GitHub Desktop.
Run an array of promises in sequence
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 results = [] | |
return arrayOfPromises.reduce((chain, promise, i) => | |
chain.then((result) => { | |
if (i > 0) results[i-1] = result | |
return promise | |
}) | |
, Promise.resolve()) | |
.then((lastResult) => results.push(lastResult)) | |
.then(() => results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment