UNPKG

@rimbu/common

Version:

Common types and objects used in many other Rimbu packages

46 lines 2.04 kB
export var AsyncOptLazy; (function (AsyncOptLazy) { /** * Returns the value or promised value contained in an `AsyncOptLazy` instance of type T. * @param optLazy - the `AsyncOptLazy` value of type T * @param args - when needed, the extra arguments to pass to the lazy invocation * @typeparam T - the value type * @typeparam A - (default: []) types of the argument array that can be passed in the lazy case * @example * ```ts * 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) * ``` */ function toMaybePromise(optLazy, ...args) { if (optLazy instanceof Function) return optLazy(...args); return optLazy; } AsyncOptLazy.toMaybePromise = toMaybePromise; /** * Returns the value contained in an `AsyncOptLazy` instance of type T as a promise. * @param optLazy - the `AsyncOptLazy` value of type T * @param args - when needed, the extra arguments to pass to the lazy invocation * @typeparam T - the value type * @typeparam A - (default: []) types of the argument array that can be passed in the lazy case * @example * ```ts * 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) * ``` */ async function toPromise(optLazy, ...args) { if (optLazy instanceof Function) return optLazy(...args); return optLazy; } AsyncOptLazy.toPromise = toPromise; })(AsyncOptLazy || (AsyncOptLazy = {})); //# sourceMappingURL=async-optlazy.mjs.map