finally (callback, label) Promise
finally will be invoked regardless of the promise's fate just as native try/catch/finally behaves
Synchronous example:
findAuthor() {
if (Math.random() > 0.5) {
throw new Error();
}
return new Author();
}
try {
return findAuthor(); // succeed or fail
} catch(error) {
return findOtherAuther();
} finally {
// always runs
// doesn't affect the return value
}
Asynchronous example:
findAuthor().catch(function(reason){
return findOtherAuther();
}).finally(function(){
// author was either found, or not
});
Parameters:
-
callback
Function -
label
String - optional string for labeling the promise. Useful for tooling.
Returns:
-
Promise
Please login to continue.