Skip to content

Instantly share code, notes, and snippets.

@barvian
Created October 3, 2017 21:53
Show Gist options
  • Save barvian/d0004b9404f0ea455c7f50bcf58f4f43 to your computer and use it in GitHub Desktop.
Save barvian/d0004b9404f0ea455c7f50bcf58f4f43 to your computer and use it in GitHub Desktop.
Run an array of promises in sequence
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