Skip to content

Instantly share code, notes, and snippets.

@akumbhani66
Created May 30, 2019 10:42
Show Gist options
  • Save akumbhani66/8aa194a5271ea807bcf9b473c44b9a8c to your computer and use it in GitHub Desktop.
Save akumbhani66/8aa194a5271ea807bcf9b473c44b9a8c to your computer and use it in GitHub Desktop.
no await inside for-loop
const arrayOfData = [1, 2, 3, 4]
const promises = [];
for (let i = 0; i < arrayOfData.length; i += 1) {
// Don't use await here, as each request needs to wait untill previous not complete.
// Let's push all the promise and resolve them once instea
// await someAPI(arrayOfData[i])
promises.push(someAPI(arrayOfData[i]));
}
// Resolve all the promoses here.
const arrayOfResult = await Promise.all(promises);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment