I have two promises, independent of each other and I want to do a finally step after both of the promises are completed (either rejects or resolves).
$q.all() cannot be used as I want the finally to always execute (only once for both promises) even if any of the promises rejects
One solution could be to have a counter and have a finallyHandler function to execute it when both promises resolves/rejects.
var count = 0;
function finallyHandler() {
if ( ++count === 2 ) {
doStuff();
count = 0;
}
}
firstPromise.finally(finallyHandler);
secondPromise.finally(finallyHandler);
This can work but doesn't look right.
Is there any better way to do this?