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

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

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