Promise & 错误中断请求 解决地狱回调

运行流程 reject时直接弹出 resolve时继续

使用 throw 链接会中断
20220510
使用流程为等待上一函数返回即继续
BUG: 无法抓取到内部报错

let fun = function(num) {
    return new Promise(function(resolve,reject){
        console.log(`run ${num}`);
        setTimeout(()=>{
            console.log(`back ${num}`);
            resolve(3);
        },1000)
    })
}

fun('a').then(async()=>{
    console.log('cb a');
    await fun('b');
}).then(async ()=>{
    console.log('cb b');
    throw {message: 'err b!'};
    await fun('c');
}).catch(err=>{
    console.log(err);
})
posted @ 2022-03-28 09:34  qoon  阅读(136)  评论(0编辑  收藏  举报