I need a method to fire after all success and fails and I would expect .finally() to do this but I was surprised that it does not. Instead, it fires on the reject. Example code
var p3 = new Promise((resolve, reject) => {
setTimeout(() => {
console.log('three fails');
reject({ data: 'three' });
}, 2000);
});
var p4 = new Promise((resolve, reject) => {
setTimeout(() => {
console.log('four succeeds');
resolve({ data: 'four' });
}, 3000);
});
Promise.all([p3, p4])
.finally(() => console.log('Promise.all() finally fires.'));
gives the following console logs in this order
three fails
Promise.all().finally fires.
four succeeds
My only alternative would be to possible have .then and .catch both fire resolves but that would be pretty clunky.
Could someone point out a method that does what I'm looking for and/or have an explanation why finally is failing to fire after all promises complete?