Skip to main content

namespace AsyncOptLazy

A potentially lazy and/or asynchronous value of type T.

Companion type: AsyncOptLazy<T,A>

Functions

toMaybePromise

Returns the value or promised value contained in an AsyncOptLazy instance of type T.

Definition

function toMaybePromise<T, A extends any[] = []>(optLazy: AsyncOptLazy<T, A>, ...args: A): MaybePromise<T>;

Type parameters
NameDescription
Tthe value type
A(default: []) types of the argument array that can be passed in the lazy case

Parameters

NameTypeDescription
optLazyAsyncOptLazy<T, A>the AsyncOptLazy value of type T
argsAwhen needed, the extra arguments to pass to the lazy invocation
example
AsyncOptLazy.toMaybePromise(1)              // => 1
AsyncOptLazy.toMaybePromise(() => 1) // => 1
AsyncOptLazy.toMaybePromise(() => () => 1) // => () => 1
AsyncOptLazy.toMaybePromise(async () => 1) // => Promise(1)
AsyncOptLazy.toMaybePromise(Promise.resolve(1)) // => Promise(1)

toPromise

Returns the value contained in an AsyncOptLazy instance of type T as a promise.

Definition

function toPromise<T, A extends any[] = []>(optLazy: AsyncOptLazy<T, A>, ...args: A): Promise<T>;

Type parameters
NameDescription
Tthe value type
A(default: []) types of the argument array that can be passed in the lazy case

Parameters

NameTypeDescription
optLazyAsyncOptLazy<T, A>the AsyncOptLazy value of type T
argsAwhen needed, the extra arguments to pass to the lazy invocation
example
AsyncOptLazy.toPromise(1)              // => Promise(1)
AsyncOptLazy.toPromise(() => 1) // => Promise(1)
AsyncOptLazy.toPromise(() => () => 1) // => Promise(() => 1)
AsyncOptLazy.toPromise(async () => 1) // => Promise(1)
AsyncOptLazy.toPromise(Promise.resolve(1)) // => Promise(1)