Skip to content

Instantly share code, notes, and snippets.

@eugenserbanescu
Last active April 4, 2019 08:51
Show Gist options
  • Save eugenserbanescu/c5cfda2fb82b169dee897c75064c301a to your computer and use it in GitHub Desktop.
Save eugenserbanescu/c5cfda2fb82b169dee897c75064c301a to your computer and use it in GitHub Desktop.
async mapping
async function waitForStuff(i) {
return new Promise((resolve) => {
setTimeout(() => resolve(`yay!`), 100)
})
}
async function main() {
const mapped = Promise.all([1,2,3,4].map(async (item) => {
const res = await waitForStuff()
return res
}))
return mapped
}
async function other() {
return Promise.all([1,2,3,4].map(waitForStuff))
}
main().then(mapped => console.log('finished', mapped))
other().then(mapped => console.log('finished', mapped))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment