IOS下 Promise.finally 是undefined 的
发布于 7 年前 作者 shina 11293 次浏览 来自 官方Issues

使用了一个方法:

Promise.all(setTagList)
                .catch(err => {
                    console.log('出现了错误诶!!!! => ', err)
                })
                .finally(() => {
                const msgBody = {
                    event: {
                        event_type: 'ENTER'
                    }
                }
 
                console.log('come into finally')
 
                that.sendMsg(msgBody, 'enter')
            })

这个代码在安卓机器以及开发工具上都表现良好,在线上环境发现IOS的机器稳定出现问题,经过排查发现:

表现行为不一致,要么安卓和IOS都不可行,要么都可行

1 回复

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 })

    );

};

Promise.all(setTagList).then(res=>{}, fail=>{}).finally(()=>{})

catch的话,放到new Promise()里吧

new Promise(function (resolve, reject) {

    try{

    

    ****

        resolve(b);

    } catch (e) {

        reject(e);

    }

})

回到顶部