Promise.add 方法:将多个 promise 实例,包装成一个新的 promise 实例。

const p = Promise.all([p1, p2, p3]);

接受一个数组作为参数,p1, p2, p3 都是 promise 实例,

const p1 = new Promise((resolve, reject) => {
  resolve('hello');
}).then(res => res);

const p1 = new Promise((resolve, reject) => {
  throw new Error('报错');
}).then(res => res);

Promise.all([p1, p2])
.then(res => console.log(res))
.catch(e => console.log(e))

// Error : 报错

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2023-02-03
  • 2022-03-01
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
  • 2021-05-18
相关资源
相似解决方案