I want to execute when either a .then or a .catch is called. Typically this is handled with a .always
var done = function(response) { console.log('response', response) }
var fail = function(error) { console.log('error', error) }
var always = function() { console.log('always') }
Promise.resolve(42).then(done).catch(fail).then(always, always)
@chovy Unfortunately, Promises don't have an .always() method. You need to attach an always handler as both resolve and error handler to cover both cases. Clumsy, I know!
So how do we execute an always call?
@rustanacexd: See @dgraham's code above.
I did this:
class Platform {
static init() {
if(!Promise.prototype.finally) {//.finally is not supported by promise for iOS: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally
Promise.prototype.finally = function(callback) {
return this.then(callback)
.catch(callback);
};
}
}
}
and just called Platform.init() from the application, now I can use .finally for promises as normal on iOS :).
Most helpful comment