美文网首页
promise to await

promise to await

作者: LittleAnt | 来源:发表于2021-07-05 22:54 被阅读0次

let a=new Promise((resolve,reject)=>{
setTimeout(()=>{reject('-1')},1000)
})

function fn(){
return a.then(res=>{
console.log(res)
return res
}).catch(err=>{
return Promise.reject(err)
// return err
})
}

function test(){

}
async function get(){
let result;
try {
result =await fn()
result.then(r=>{
console.log('in await then:',r)
})
}catch(e){
console.log('in catch:',e)
}

console.log('---',result)

}

get()

相关文章

网友评论

      本文标题:promise to await

      本文链接:https://www.haomeiwen.com/subject/slkwultx.html