The result type of the task.
The async task to wrap.
Optionaloptions: CancellableOptions<SettledResult<T>>Cancellable configuration options.
A cancellable handle that always resolves to a SettledResult.
const handle = reflect(async () => {
throw new Error("failed");
});
const result = await handle;
// result: { status: "rejected", reason: Error("failed") }
// Use with parallel to get all results
import { parallel, reflect } from "@vgerbot/async";
const results = await parallel({},
reflect(async () => "success"),
reflect(async () => { throw new Error("fail"); }),
reflect(async () => 42),
);
// results: [
// { status: "fulfilled", value: "success" },
// { status: "rejected", reason: Error("fail") },
// { status: "fulfilled", value: 42 },
// ]
Wraps a task to always resolve (never reject). Returns a result object indicating success or failure. Useful for handling errors without try-catch or for parallel operations where you want all results regardless of failures.