Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

186
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda