Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
How to run 2 for await loops in parallel?

I have this code:

for await (const thing of signal()) {
    // logic
}

for await (const thing of anotherSignal()) {
    // logic
}

The problem is that these for awaits run forever. So the second one never executes. Is there a way to make these 2 loops run in parallel?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Don't wait for first task to complete, Run them parallel, Like So:

let delay = ms => new Promise(ok => setTimeout(ok, ms));
async function* infinit_iter() {
  for (let i = 0;; i++) {
    await delay(3000)
    yield i
  }
}

async function run(name, iter) {
  for await (let i of iter)
    console.log(name, i)
}

run("signal:", infinit_iter())
run("anotherSignal:", infinit_iter())

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!