Member-only story
Javascript: Promise Static Methods
6. Deep dive into Promise Static Methods
In this article, we are talking about Static Methods of Promise and itโs implementation. Promise Static Methods are either fullfill, reject or settle(fullfill or reject) .
1. Promise.all
This returned promise fulfills when all of the inputโs promises fulfill (including when an empty iterable is passed)
Output: An Array
Success: When, All of the promises fulfill
const p1 = Promise.resolve(3);
const p2 = 42;
const p3 = new Promise((resolve) => setTimeout(() => resolve('foo')));
const p4 = new Promise((r, reject) => setTimeout(() => reject('Rejected')));var allPormiseResolved = Promise.all([p1, p2, p3]);
allPormiseResolved.then((values) => {
console.log(values); // Expected output: Array [3, 42, "foo"]
});var onePromiseFailed = Promise.all([p1, p2, p4]);
onePromiseFailed.catch((values) => {
console.log(values); // Expected output: Rejected
});2. Promise.allSettled
This returned promise fulfills when all of the inputโs promises settle(Either fail or success).
Output: An Array
Success: All of the promises settle









