I am in search of a method to retrieve both successful resolutions and rejections from a promise array. I am relying on the Bluebird implementation, so any ES6 compatible solution would be preferable.
One option that comes to mind is utilizing Bluebird's Promise.settle
for this purpose, as I find promise inspections to be an unnecessary complication:
let promises = [
Promise.resolve('resolved'),
Promise.resolve('resolved'),
Promise.reject('rejected')
];
// wondering if there is a way to achieve this
let resolvedAndRejected = Promise.settle(promises)
.then((inspections) => {
let resolved = [];
let rejected = [];
inspections.forEach((inspection) => {
if (inspection.isFulfilled())
resolved.push(inspection.value());
else if (inspection.isRejected())
rejected.push(inspection.reason());
});
return [resolved, rejected];
});
resolvedAndRejected.spread((resolved, rejected) => {
console.log(...resolved);
console.error(...rejected);
});
This seems like a straightforward task for scenarios where achieving a 100% fulfillment rate is not essential or desired, but I am unsure what this approach is commonly referred to.
Are there any efficient and reliable ways to handle this within Bluebird or other promise implementations - whether through a built-in function or extension?