async function fetchData(id) {
if (id <= 0) throw new Error("Invalid ID");
return { id, value: id * 10 };
}
async function process() {
const results = await Promise.allSettled([
fetchData(1),
fetchData(-1),
fetchData(3),
]);
results.forEach(({ status, value, reason }) => {
if (status === "fulfilled") {
console.log(`✅ ${value.id}: ${value.value}`);
} else {
console.log(`❌ ${reason.message}`);
}
});
}
process(); Post #3341
2.6K
CHALLENGE
- ❤ 5
- 👍 1
- 🔥 1