ES6-Promise.all()使用

 

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 : 报错

 

posted @ 2018-12-08 15:50  Jaye8584  阅读(2648)  评论(0编辑  收藏  举报