Skip to content

.tip

ยท one of the small things

allSettled when one failure should not sink the rest

Promise.all rejects on the first failure and throws away the other results, even the ones that succeeded. For a fan-out where partial results are still useful, allSettled gives you every outcome.

const results = await Promise.allSettled(urls.map(fetchJson));
const ok = results.flatMap((r) => (r.status === "fulfilled" ? [r.value] : []));

Use all when the results only mean something together, and allSettled when you'd rather have nine out of ten.

javascript