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.
toMaybePromiseAsyncOptLazy instance of type T.Definition
function toMaybePromise<T, A extends any[] = []>(optLazy: AsyncOptLazy<T, A>, ...args: A): MaybePromise<T>;
Type parameters
| Name | Description |
|---|---|
| T | the value type |
| A | (default: []) types of the argument array that can be passed in the lazy case |
Parameters
| Name | Type | Description |
|---|---|---|
optLazy | AsyncOptLazy<T, A> | the AsyncOptLazy value of type T |
args | A | when 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.
toPromiseAsyncOptLazy instance of type T as a promise.Definition
function toPromise<T, A extends any[] = []>(optLazy: AsyncOptLazy<T, A>, ...args: A): Promise<T>;
Type parameters
| Name | Description |
|---|---|
| T | the value type |
| A | (default: []) types of the argument array that can be passed in the lazy case |
Parameters
| Name | Type | Description |
|---|---|---|
optLazy | AsyncOptLazy<T, A> | the AsyncOptLazy value of type T |
args | A | when 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)