Loading problem…
Implement a promiseAllSettled function that behaves like the native Promise.allSettled.
The function takes an array of promises (or values) and returns a single Promise that resolves after all inputs have settled (either fulfilled or rejected).
Unlike Promise.all, this function does not short-circuit on rejection. Instead, it waits for every input to complete and returns their outcomes.
{ status: 'fulfilled', value: result }{ status: 'rejected', reason: error }[].const p1 = Promise.resolve(1);
const p2 = Promise.reject('error');
const p3 = Promise.resolve(3);
promiseAllSettled([p1, p2, p3]).then(results => {
console.log(results);
// [
// { status: 'fulfilled', value: 1 },
// { status: 'rejected', reason: 'error' },
// { status: 'fulfilled', value: 3 }
// ]
});