二. Promise.allSettled

时间:2020-12-04 11:47:16   收藏:0   阅读:23
const p1 = new Promise((resolve, reject)=>{
      setTimeout(()=>{
            resolve(‘商品数据-1‘)
      },1000)
})

const p2 = new Promise((resolve, reject)=>{
      setTime(()=>{
            //resolve(‘商品数据-2‘)
            reject(‘出错啦‘)
      })
})      

//调用 allsettled 方法
const result = Promise.allSettled([p1,p2]);      //状态都返回

const res = Promise.all([p1,p2]);                 // 只返回成功的状态

console.log(res)

原文:https://www.cnblogs.com/wangRong-smile/p/14084111.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!