Skip to content

memoPromise ​

The memoPromise() function lazily evaluates a function that returns a value or a promise, then memoizes the resolved result.

Interactive example ​

Syntax ​

typescript
interface MemoizedPromise<
	GenericValue extends unknown
> {
	readonly value: MaybePromise<GenericValue>;
}

function memoPromise<
	GenericOutput extends unknown
>(
	theFunction: () => MaybePromise<GenericOutput>
): MemoizedPromise<GenericOutput>;

Parameters ​

  • theFunction : Function evaluated once on first access, returning a value or a promise.

Return value ​

A MemoizedPromise object with a lazy value getter. The first access returns a promise; once resolved, the property holds the resolved value.

See also ​

Released under the MIT license.