Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

104
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda