pendingOk
@ts-rust/std / Result / pendingOk
Function: pendingOk()
function pendingOk<T, E>(value): PendingResult<Awaited<T>, Awaited<E>>;
Defined in: packages/std/src/result/result.ts:376
Creates a PendingResult\<T, E\> that resolves to Ok containing the awaited value.
Takes a value or promise and wraps its resolved result in an Ok,
ensuring the value type is Awaited
to handle any PromiseLike
input.
Type Parameters
Type Parameter | Description |
---|---|
| The type of the input value or promise. |
| The type of the potential error. |
Parameters
Parameter | Type | Description |
---|---|---|
|
| The value or promise to wrap in Ok. |
Returns
PendingResult
<Awaited
<T
>, Awaited
<E
>>
A PendingResult resolving to Ok with the awaited value.
Example
const x = pendingOk<number, string>(42);
const y = pendingOk<string, number>(Promise.resolve("hello"));
expect(await x).toStrictEqual(ok(42));
expect(await y).toStrictEqual(ok("hello"));