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

144
Visualizações
Does the for loop block when the iteration invokes an async function without await keyword? (the invoked async function has the await keyword)

In the below pseudocode, when the for loop executes each iteration, then will the for loop block at each iteration waiting for the response of the async fetch (because await is used within the myasyncfn? Or do I need to use await keyword as shown in the comment below?

async myasyncfn(url){
return await fetch(url..).response;
}

for each url in url_array:
   myasyncfn(url);    #await myasyncfn(url)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It will not wait for the async function to complete before continuing the loop; in that sense, it will block. However, that just means it iterates through all URLs in quick succession, firing many fetch requests, which will then all run in the background in parallel. Once the loop is done firing those, your thread is unblocked.

To illustrate:

async function foo(i) {
    await new Promise(resolve => setTimeout(resolve, 5000));
    console.log('Completed', i);
}

for (let i = 0; i < 10; i++) {
    foo(i);
    console.log('Fired', i);
}

console.log('Done firing all async functions, unblocking...');

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