面试题多个 await 处理,有一个失败,就算作失败 ?

Promise.all([p1, p2, p3....])    // 返回的也是一个 Promise 对象 -------- asait异步成功返回一个数组[result, result]

解决: 一次发送多个请求,等所有请求都返回后再一起处理,如果一个请求出错,整个都会失败

  • Promise.all([]).then(results=>{
        // results 是一个 {status: 0, data:{....}} 数组 
    })
    
    // 或者
    const results = await Promise.all([reqCategory(pCategoryId), reqCategory(pCategoryId)]);

相关文章:

  • 2021-12-19
  • 2021-10-20
  • 2022-01-30
  • 2021-05-10
  • 2021-06-28
  • 2022-12-23
  • 2021-10-02
猜你喜欢
  • 2021-09-29
  • 2022-12-23
  • 2022-02-05
  • 2021-07-08
  • 2022-01-06
  • 2021-12-18
相关资源
相似解决方案