首页 > 解决方案 > nodejs Promise.allSettled 的“已完成”和“已拒绝”常量

问题描述

我最近一直在使用Promise.allSettled并行运行异步方法并收集成功/失败的结果。

我通常会做类似的事情:

const results = await Promise.allSettled([doSomething(), doSomethingElse()]);
const happy = results.filter((result) => result.status === "fulfilled").map((result) => result.value);
const sad = results.filter((result) => result.status === "rejected").map((result) => result.reason);

"fulfilled"我想知道字符串和是否有任何常量"rejected"

标签: javascriptnode.jses6-promise

解决方案


推荐阅读