Skip to content

Instantly share code, notes, and snippets.

@etoxin
Created February 8, 2018 00:23
Show Gist options
  • Save etoxin/ea3f2fd8fa35f31819195950fd998ec8 to your computer and use it in GitHub Desktop.
Save etoxin/ea3f2fd8fa35f31819195950fd998ec8 to your computer and use it in GitHub Desktop.
Parallelism

Parallelism

Google's Jake Archibald make excellent points in the Async functions document about not getting too sequential with your awaits. The idea is to avoid stacking awaits, when possible, and instead trigger tasks immediately and use await after said tasks are triggered:

// Will take 1000ms total!
async function series() {
await wait(500);
await wait(500);
return "done!";
}
// Would take only 500ms total!
async function parallel() {
const wait1 = wait(500);
const wait2 = wait(500);
await wait1;
await wait2;
return "done!";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment