Skip to content

Instantly share code, notes, and snippets.

@ilomon10
Created September 19, 2020 10:12
Show Gist options
  • Save ilomon10/6fac60f6388019c66fdddcc83cea0dd6 to your computer and use it in GitHub Desktop.
Save ilomon10/6fac60f6388019c66fdddcc83cea0dd6 to your computer and use it in GitHub Desktop.
Async await in loop
/**
* 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