Question 56 of 10056%
56
What gets logged when comparing Promise.all and Promise.allSettled in this code?
async function run() {
const promises = [
new Promise((resolve) => {
setTimeout(() => resolve("first"), 20);
}),
Promise.reject("Boom!"),
Promise.resolve("last"),
];
try {
const values = await Promise.all(promises);
console.log("all:", values.join(", "));
} catch (reason) {
console.log("all:", reason);
}
const results = await Promise.allSettled(promises);
console.log(
"settled:",
results.map((result) =>
result.status === "fulfilled"
? `fulfilled: ${result.value}`
: `rejected: ${result.reason}`
).join(", ")
);
}
run();
56/100