@vgerbot/async
    Preparing search index...

    Function reflect

    • 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.

      Type Parameters

      • T

        The result type of the task.

      Parameters

      Returns CancellableHandle<SettledResult<T>>

      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 },
      // ]