An array of promises.
A promise that resolves to an array of settled results.
async function getUser(name: string): Promise<{ id: string }> {...}
const results = await allSettled([
getUser('alice'),
getUser('nonexistent'), // will be rejected
])
// results[0].isFulfilled // true
// results[1].isRejected // true
results.forEach((result) => {
if (result.isFulfilled) {
result.value // type: { id: string }
} else {
result.reason // type: unknown (Error)
}
})
import { isFulfilled, partition } from "uft";
const [fulfilled, rejected] = partition(results, isFulfilled)
fulfilled.forEach((result) => {
result.value // type: { id: string }
})
rejected.forEach((result) => {
result.reason // type: unknown (Error)
})
Generated using TypeDoc
Typed version of Promise.allSettled, which defines two additional properties on the result:
isFulfilled
andisRejected
.