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

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

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