Created
May 30, 2019 10:42
-
-
Save akumbhani66/8aa194a5271ea807bcf9b473c44b9a8c to your computer and use it in GitHub Desktop.
no await inside for-loop
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 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