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

72
Views
Need to executed all requests in the array in parallel

I found that task.

Description

  1. It is necessary to execute all requests in the array in parallel.
  2. No more than 5 at a time.
  3. If the request returned an error, go ahead.
  4. If the 3rd returned the result, we make another request, and so on ...
  5. Finally, return an array of all successful queries.
const list = ["get0", "get1", "get2", "get3", "get4", "get5", "get6", "get7", "get8", "get9"];
const maxQuery = 5;

const customFetch = (url) =>
    new Promise((resolve, reject) => {
        if (Math.random() < 0.2) {
            setTimeout(() => reject("Error: " + url), (Math.random() * 1500) | 0);
        } else {
            setTimeout(() => resolve("Some data: " + url), (Math.random() * 500) | 0);
        }
    });

async function getData(list) {
    // ...
    // some code
    // ...
}

getData(list).then((result) => console.log(result));

But I haven't the solution. I guess I could be use Promise and cycle "for of" for work with async operations. But I can't combinate it. Please any solutions for this

about 4 years ago · Juan Pablo Isaza
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!