Skip to content

Instantly share code, notes, and snippets.

@yuki-takeichi
Last active May 13, 2018 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuki-takeichi/ed8b207625f175de4ba4867440187499 to your computer and use it in GitHub Desktop.
Save yuki-takeichi/ed8b207625f175de4ba4867440187499 to your computer and use it in GitHub Desktop.
JS AwaitAll is all what we want.
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