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);

浙公网安备 33010602011771号