Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

268
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!