Promise.all vs Promise.allSettled in Javascript

Promise.all and Promise.allSettled is used to iterate over an array of promises. However, both have a few subtle differences, let's understand that in this article.

Promise.all method

Promise.all iterates over an array of promises and resolve to the array of values returned by each promise.

promise-all-example.js
1const tasks = [ 2 new Promise((resolve, reject)=> { 3 setTimeout(resolve, 1000, "task 1") 4 }), 5 new Promise((resolve, reject)=> { 6 setTimeout(resolve, 2000, "task 2") 7 }), 8 new Promise((resolve, reject)=> { 9 setTimeout(resolve, 3000, "task 3") 10 }), 11] 12Promise.all(tasks).then(data => { 13 console.log(data); // ["task 1", "task 2", "task 3"] 14})

If any one of the promises gets rejected then it immediately stops the execution and rejects with the error returned from the rejected promise.

promise-all-with-error.js
1const tasks = [ 2 new Promise((resolve, reject)=> { 3 setTimeout(resolve, 1000, "task 1") 4 }), 5 new Promise((resolve, reject)=> { 6 setTimeout(reject, 2000, "task 2 failed") 7 }), 8 new Promise((resolve, reject)=> { 9 setTimeout(resolve, 3000, "task 3") 10 }), 11] 12Promise.all(tasks).then(data => { 13 console.log(data); 14}).catch(error => { 15 console.log(error); // task 2 failed 16})

Promise.allSettled method

Promise.allSettled iterates over an array of promises and waits for all the promises to get either resolved or rejected. It resolves to an array of data with each promise's status in the following format.

allsettled-format.js
1[ 2{status: "fulfilled", value: value1}, 3{status: "fulfilled", value: value2}, 4{status: "rejected", reason: error} 5]

Let's see what will be the output of the tasks

promise-allsettled-example.js
1const tasks = [ 2 new Promise((resolve, reject)=> { 3 setTimeout(resolve, 1000, "task 1") 4 }), 5 new Promise((resolve, reject)=> { 6 setTimeout(reject, 2000, "task 2 failed") 7 }), 8 new Promise((resolve, reject)=> { 9 setTimeout(resolve, 3000, "task 3") 10 }), 11] 12Promise.allSettled(tasks).then(data => { 13 console.log(data); 14}) 15 16// Output 17[ 18{ 19 status: 'fulfilled', 20 value: 'task 1', 21}, 22{ 23 status: 'rejected', 24 reason: 'task 2 failed', 25}, 26{ 27 status: 'fulfilled', 28 value: 'task 3', 29}, 30];
AvatarKaran Kiri

© 2025 Karan Kiri. All rights reserved.