pendingOption
@ts-rust/std / Option / pendingOption
Function: pendingOption()
function pendingOption<T>(optionOrFactory): PendingOption<T>;
Defined in: packages/std/src/option/option.ts:138
Creates a PendingOption\<T\> from an option, promise, or factory function.
Accepts an Option, a Promise
resolving to an Option, or
a function returning either, and converts it into a pending option, handling
asynchronous resolution as needed.
Type Parameters
Type Parameter | Description |
---|---|
| The type of the value in the option. |
Parameters
Parameter | Type | Description |
---|---|---|
| | | The Option, promise, or factory function producing an Option. |
Returns
A PendingOption resolving to the provided or produced option.
Example
const x = pendingOption(some(42));
const y = pendingOption(() => Promise.resolve(none<string>()));
const z = pendingOption(async () => some("thing"));
expect(await x).toStrictEqual(some(42));
expect(await y).toStrictEqual(none());
expect(await z).toStrictEqual(some("thing"));