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

149
Views
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 answers
Answer question

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 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!