Created
September 19, 2020 10:12
-
-
Save ilomon10/6fac60f6388019c66fdddcc83cea0dd6 to your computer and use it in GitHub Desktop.
Async await in loop
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
/** | |
* Ref: https://zellwk.com/blog/async-await-in-loops/ | |
*/ | |
const mapLoop = async _ => { | |
console.log('Start') | |
const promises = fruitsToGet.map(async fruit => { | |
const numFruit = await getNumFruit(fruit) | |
return numFruit | |
}) | |
const numFruits = await Promise.all(promises) | |
console.log(numFruits) | |
console.log('End') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment