@itwin/core-backend
Version:
iTwin.js backend components
48 lines • 1.91 kB
TypeScript
/** Wrapper around a promise that allows synchronous queries of it's state
* @internal
*/
export declare class QueryablePromise<T> {
readonly promise: Promise<T>;
result?: T;
error?: any;
private _fulfilled;
private _rejected;
get isPending(): boolean;
get isFulfilled(): boolean;
get isRejected(): boolean;
constructor(promise: Promise<T>);
}
/** @internal */
export type MemoizeFnType<T> = (...args: any[]) => Promise<T>;
/** @internal */
export type GenerateKeyFnType = (...args: any[]) => string;
/** Utility to cache and retrieve results of long running asynchronous functions.
* The cache is keyed on the input arguments passed to these functions
* @internal
*/
export declare class PromiseMemoizer<T> implements Disposable {
private readonly _cachedPromises;
private readonly _timers;
private readonly _memoizeFn;
private readonly _generateKeyFn;
private readonly _maxCacheSize;
private readonly _cacheTimeout;
/**
* Constructor
* @param memoizeFn Function to memoize
* @param generateKeyFn Function to generate the key for the memoized function
* @param maxCacheSize Maximum size of the memoizer cache.
* If the maximum cache size is exceeded, fulfilled/rejected entries are first discarded - these
* may have been unclaimed/orphaned promises. If the cache size is still above the maxCacheSize
* threshold, the entire cache is then cleared.
*/
constructor(memoizeFn: MemoizeFnType<T>, generateKeyFn: GenerateKeyFnType, maxCacheSize?: number, cacheTimeout?: number);
/** Call the memoized function */
memoize(...args: any[]): QueryablePromise<T>;
/** Delete the memoized function */
deleteMemoized(...args: any[]): void;
/** Clear all entries in the memoizer cache */
clearCache(): void;
[Symbol.dispose](): void;
}
//# sourceMappingURL=PromiseMemoizer.d.ts.map