Tuan-Anh Tran

Series and parallel execution with async/await

Posted on January 9, 2018  •  1 minutes  • 70 words

TIL

series

async function series() {
  await wait(500); // Wait 500ms…
  await wait(500); // …then wait another 500ms.
  return "done!";
}

parallel

async function parallel() {
  const wait1 = wait(500); // Start a 500ms timer asynchronously…
  const wait2 = wait(500); // …meaning this timer happens in parallel.
  await wait1; // Wait 500ms for the first timer…
  await wait2; // …by which time this timer has already finished.
  return "done!";
}
Follow me

Here's where I hang out in social media