ts-data-forge
    Preparing search index...
    • Converts a Promise into a Promise that resolves to a Result. If the input Promise resolves, the Result will be Ok with the resolved value. If the input Promise rejects, the Result will be Err with the rejection reason.

      Type Parameters

      • P extends Promise<unknown>

        The type of the input Promise.

      Parameters

      • promise: P

        The Promise to convert.

      Returns Promise<Result<UnwrapPromise<P>, unknown>>

      A Promise that resolves to Result<UnwrapPromise<P>, unknown>.

      const successPromise = Result.fromPromise(Promise.resolve('ok'));
      const failurePromise = Result.fromPromise(Promise.reject(new Error('fail')));

      const resolved = await successPromise;
      const rejected = await failurePromise;

      assert.deepStrictEqual(resolved, Result.ok('ok'));
      assert.ok(Result.isErr(rejected));