Last active
May 13, 2018 06:39
-
-
Save yuki-takeichi/ed8b207625f175de4ba4867440187499 to your computer and use it in GitHub Desktop.
JS AwaitAll is all what we want.
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
const timeout = ms => | |
new Promise((resolve, reject) => setTimeout(() => resolve(), ms)); | |
async function f() { | |
await timeout(500); | |
return 'f'; | |
} | |
async function g() { | |
await timeout(1000); | |
return 'g'; | |
} | |
async function main() { | |
const [x, y] = await Promise.all([f(), g()]); | |
// Actually, I wanted to write this: | |
//const [x, y] = awaitall f(), g(); | |
console.log(x); | |
console.log(y); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment