Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda