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

207
Vistas
JavaScript, detect when a promise in an array of promises is resolved then do something with it

I have the following code :-

      for (let i = 0; i < fdlist.length; i++) {
        let request = fetch(`${domain}/segment?mode=${mode}&type=${type}`,  {    method: 'POST', body: fdlist[i]   }).then((res) => res.json());
        requestlist.push(request)
        console.log(requestlist)
        }
        const allData = Promise.all(requestlist);
        allData.then(async (res) => { 

It sends multiple fetch requests and pushes each one of them to a list, then I do a Promise.all to wait for all of them to resolve and process all the results at once.

My question is, how can I process the promises that resolve right away instead of waiting for all the promises to resolve to begin processing?

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

just loop through the promises and add "then" clauses:

for (const p of requestlist) {
  p.then(result => ...)
}

// you can always still wait for them all if you want
Promise.all(requestlist).then(...)

you can add your then at the start when you fetch:


for (...) {
  let request = fetch(...)
  const processed = request.then(response => ...)
  requestlist.push(processed)
}

// wait for it all here if you still want
Promise.all(requestlist).then(...)
about 4 years ago · Santiago Gelvez 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