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

157
Views
How can I skip a promise if it is not completed

I have an array of 100,000 URLs. I want to loop through the array and fetch the URL contents. I am splitting the array dynamically so each time it will take 20 URLs from array (In order to prevent memory overflow due to size of content fetched from every URL) and form new array with the 20 URLs. The problem I am facing is since I am using Promise.all if any one of the request is in pending state it will pause the further execution. I want to skip the pending promise after certain time and the loop should continue to work

(async () => {
    while(allUrls.length) {
        const splittedUrlsArray = allUrls.splice(0, 20); // splitting large array of urls to small arrays of 20 urls
        const urlContents = await getUrlContents(splittedUrlsArray);
        urlContents.map(async (item) => {
        })
    }
})()

const getUrlContents = (urls) => {
    const promises = urls.map( async (url) => {
        try {
            const res = await axios.get(url);
            return res;
        } catch(err) {
            console.log(err);
        }
    })
    return Promise.all(promises);
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Standard operation for web robots is to use a queue. Since you're using promises, try looking at something like this: https://www.npmjs.com/package/async-await-queue

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!