Last active
April 4, 2019 08:51
-
-
Save eugenserbanescu/c5cfda2fb82b169dee897c75064c301a to your computer and use it in GitHub Desktop.
async mapping
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
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