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

185
Vistas
Multiple awaits in for loop how to fix?

I have a for loop with multiple awaits and have no idea how to Promise.all each one so that I can remove the "Unexpected await inside a loop" esLint error. I have seen examples of fixes with Promise.all but it is for only 1 await. My loop has 3 awaits. Here is my code:

for (let i = 0; i < a.length; i++) {
    let b = await http.get(...)
    let c = await http.get(...)
    await doSomethingElse(i, b, c);
}

how do I remove all the awaits? without doing so my whole function will fail

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can Promise.all:

  • Each iteration of the loop
  • The requests for b and c, because neither is dependent on the other
Promise.all(
    a.map(
        (_, i) => Promise.all([
            http.get(...), // gets b
            http.get(...), // gets c
        ])
            .then(([b, c]) => doSomethingElse(i, b, c))
    )
)
    .then(() => {
        // everything is finished
    });
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