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

271
Vistas
Promise.all should be rejected, but is actually fulfilled?

I'm newer to JavaScript and thought I understood the basics of Promises, but I am definitely missing something here.

The basic idea here is I am chaining a couple of promises together.

promise3 does some initial work and if it succeeds, then we do some more work. The second stage of this chain is a couple of promises, promise1 and promise2. Because promise2 is rejected, the end result I had expected was that Promise.all rejects, and therefore I expected the result in Promise.allSettled to also be rejected.

However, what I am observing is that the first promise in the chain here determines the result of the chain - if it is resolved then the result is resolved, but if it is rejected then result is rejected.

Why is this the case?

const promise1 = Promise.resolve(1);
const promise2 = Promise.reject(2)
const promise3 = Promise.resolve(3);
const promises = [promise1, promise2];

const p = [ promise3.then(Promise.all(promises)) ]

Promise.allSettled(p).
  then((results) => results.forEach((result) => console.log(result.status)))

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This is because your code is wrong. then expects a callback, but provides a value of Promise.all(...)

The corrected code is

 const promise1 = Promise.resolve(1); const promise2 = Promise.reject(2) const promise3 = Promise.resolve(3); const promises = [promise1, promise2]; const p = [ promise3.then(() => Promise.all(promises)) ] Promise.allSettled(p). then((results) => results.forEach((result) => console.log(result.status)))

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