promise的all和race的效果对比

阅读 121

2022-11-05


promise的all和race的效果对比

function fun1(){
return new Promise(_=>{
setTimeout(()=>{
_("1")
},1000)
})
}


function fun2(){
return new Promise(_=>{
setTimeout(()=>{
_("2")
},2000)
})
}

Promise.all([fun1(),fun2()]).then((ret)=>{
console.log("all",ret);
})

Promise.race([fun1(),fun2()]).then((ret)=>{
console.log("rece",ret);
})


相关推荐

精彩评论(0)

0 0 举报