Skip to main content

pendingOk

@ts-rust/std


@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 ParameterDescription

T

The type of the input value or promise.

E

The type of the potential error.

Parameters

ParameterTypeDescription

value

T | Promise<T>

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"));