Promise.prototype.finally()
Promise.prototype.finally()
Method, regardless of success or failure will be executed on a promise, and the resolution will be passed through on a promise of the case, carefully understand the following example default:
var p = Promise.resolve('ok')
.finally(() => {
return Promise.reject('这里只有返回被拒绝的 promise 或者 throw 一个错误,才会影响当前 finally 返回的新 promise 的决议') })
.then(value => {
console.log('成功', value)
}, (err) => {
console.log('失败', err)
});
Summary:
limited impact on the promise their resolution finally returned, it can be changed to resolve on a reject, it can be changed to another on a reject reject, but can not put on a reject changed to resolve.