ES11——批量处理异步任务 allSettled 与 all

Promise.allSettled() 不论状态是否为 true 都会继续执行

const p1 = new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve("商品-1");  //成功
  }, 1000);
});
const p2 = new Promise((resolve, reject) => {
  setTimeout(() => {
    reject("商品-2");  //失败
  }, 1000);
});

const res = Promise.allSettled([p1, p2]);
console.log(res);

Promise.all() 必须全部状态都为 true 才会执行

const res = Promise.all([p1, p2]);
console.log(res);

posted on 2021-08-10 23:19  In-6026  阅读(144)  评论(0)    收藏  举报

导航