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

158
Visualizações
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 Respostas
Responde à pergunta

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