Skip to content

Instantly share code, notes, and snippets.

@xMartin
Created February 15, 2017 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xMartin/6710a60c12a2f06491d8ef92e2c70a69 to your computer and use it in GitHub Desktop.
Save xMartin/6710a60c12a2f06491d8ef92e2c70a69 to your computer and use it in GitHub Desktop.
Running n async operations sequentially in JavaScript with Promises (note the re-assignment of `promise`)
const n = 10
let promise = Promise.resolve()
for (let i = 0; i < n; ++i)
promise = promise.then(doSomethingAsync)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment