小程序中增加对promise.finally操作的支持 (#458)

This commit is contained in:
Longmain
2021-01-18 21:38:42 +08:00
committed by GitHub
parent 46d2a4e080
commit 69de3b5418
2 changed files with 24 additions and 0 deletions

View File

@@ -4,6 +4,17 @@ var user = require('./utils/user.js');
App({ App({
onLaunch: function() { onLaunch: function() {
Promise.prototype.finally = function(callback){
let P = this.constructor;
return this.then(
value => {
P.resolve(callback()).then(() => value)
},
reason => {
P.resolve(callback()).then(() => { throw reason })
}
)
}
const updateManager = wx.getUpdateManager(); const updateManager = wx.getUpdateManager();
wx.getUpdateManager().onUpdateReady(function() { wx.getUpdateManager().onUpdateReady(function() {
wx.showModal({ wx.showModal({

View File

@@ -4,7 +4,20 @@ var user = require('./utils/user.js');
App({ App({
onLaunch: function() { onLaunch: function() {
Promise.prototype.finally = function(callback){
let P = this.constructor;
return this.then(
value => {
P.resolve(callback()).then(() => value)
},
reason => {
P.resolve(callback()).then(() => { throw reason })
}
)
}
const updateManager = wx.getUpdateManager(); const updateManager = wx.getUpdateManager();
wx.getUpdateManager().onUpdateReady(function() { wx.getUpdateManager().onUpdateReady(function() {
wx.showModal({ wx.showModal({
title: '更新提示', title: '更新提示',