Sobes.tech
Junior — Middle

Will Promise.all continue execution if one of the promises passed to it fails?

sobes.tech AI

Answer from AI

No, Promise.all will not continue to wait for the remaining promises if one of them is rejected. In this case, Promise.all immediately rejects with that error, and the execution of the other promises does not affect the result.

That is, if at least one promise in the array passed to Promise.all is rejected, the final promise will also be rejected with that error.

Example:

const p1 = Promise.resolve(1);
const p2 = Promise.reject(new Error('Error'));
const p3 = new Promise(resolve => setTimeout(() => resolve(3), 1000));

Promise.all([p1, p2, p3])
  .then(results => console.log('Results:', results))
  .catch(error => console.error('Error:', error.message));
// Will output: Error: Error

Note that p3 can continue to execute, but Promise.all has already rejected and does not wait for its result.