promise的all和race的效果对比

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

猜你喜欢

转载自blog.csdn.net/m0_46672781/article/details/127697740