@itsmworkbench/utils
Version:
The usual utility functions
33 lines (32 loc) • 1.69 kB
TypeScript
import { NameAnd } from "@laoban/utils";
export interface PromiseCacheListener<Context, Result> {
duplicateCall?: (context: Context) => void;
callingLoad?: (context: Context) => void;
loadAborted?: (context: Context) => void;
loadArrived?: (context: Context, result: Result) => void;
loadAbandoned?: (context: Context, reason: string) => void;
loadError?: (context: Context, e: any) => void;
info?: (context: Context, title: string, msg: string) => void;
}
/** So this only caches during the actually query
* It has two keys, and the promise is the value
* When the query finishes it removes the promise from the cache
* This is mostly for situations like 'terraform'
*
* We want to be able to compare 'desired' to 'actual'. But it takes time to do this. While that time is happening we don't want to do it again! So we return the
* current promise.
*/
export interface TwoKeyPromiseCache<Context, T> {
listeners: PromiseCacheListener<Context, T>[];
cache: NameAnd<NameAnd<Promise<T | undefined>>>;
}
export declare function getOrUpdateFromPromiseCache<Context, T>(engine: TwoKeyPromiseCache<Context, T>, context: Context, name1: string, name2: string, raw: () => Promise<T>): Promise<T | undefined>;
export type FCLogRecord<Context, T> = {
context: Context;
title: string;
msg?: string;
t?: T;
};
export declare function futureCacheConsoleLog<Context, T>(title: string): PromiseCacheListener<Context, T>;
export declare function futureCacheLog<Context, T>(array: FCLogRecord<Context, T>[]): PromiseCacheListener<Context, T>;
export declare function futureCacheLogString<Context, T>(array: string[]): PromiseCacheListener<Context, T>;