@ts-rust/std - v0.0.5
    Preparing search index...

    Function pendingResult

    • Creates a PendingResult<T, E> from a result, promise, or factory function.

      Accepts a Result, a Promise resolving to a Result, or a function returning either, and converts it into a pending result, handling asynchronous resolution as needed.

      Type Parameters

      • T

        The type of the value in the result.

      • E

        The type of the expected error in the result.

      Parameters

      • resultOrFactory:
            | Result<T, E>
            | Promise<Result<T, E>>
            | (() => Result<T, E> | Promise<Result<T, E>>)

        The Result, promise, or factory function producing a Result.

      Returns PendingResult<T, E>

      A PendingResult resolving to the provided or produced result.

      const x = pendingResult(ok<number, string>(42));
      const y = pendingResult(() => Promise.resolve(err<string, number>(42)));
      const z = pendingResult(async () => err<string, boolean>(true));

      expect(await x).toStrictEqual(ok(42));
      expect(await y).toStrictEqual(err(42));
      expect(await z).toStrictEqual(err(true));