I'm looking for the way to get both resolutions and rejections from promise array. I'm currently counting on Bluebird implementation, so ES6 compatible solution would be suitable, too.
The best thing that comes to mind is to use Bluebird's Promise.settle
for that, and I consider promise inspections an unnecessary complication here:
let promises = [
Promise.resolve('resolved'),
Promise.resolve('resolved'),
Promise.reject('rejected')
];
// is there an existing way to do 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);
});
It looks like a trivial task for the cases where 100% fulfillment rate isn't an option or a goal, but I don't even know the name for the recipe.
Is there a neat and well-proven way to handle this in Bluebird or other promise implementations - built-in operator or extension?