@epic-web/cachified
Version:
neat wrapper for various caches
21 lines (20 loc) • 942 B
TypeScript
import type { CacheMetadata, GetFreshValue, GetFreshValueContext } from './common';
type OnValueCallback<Value> = (context: GetFreshValueContext & {
value: Value;
}) => void;
export type AddFn<Value, Param> = (param: Param, onValue?: OnValueCallback<Value>) => GetFreshValue<Value>;
export type GetFreshValues<Value, Param> = (params: Param[], metadata: CacheMetadata[]) => Value[] | Promise<Value[]>;
export declare function createBatch<Value, Param>(getFreshValues: GetFreshValues<Value, Param>, autoSubmit: false): {
submit: () => Promise<void>;
add: AddFn<Value, Param>;
};
export declare function createBatch<Value, Param>(getFreshValues: GetFreshValues<Value, Param>): {
add: AddFn<Value, Param>;
};
export declare class Deferred<Value> {
readonly promise: Promise<Value>;
readonly resolve: (value: Value | Promise<Value>) => void;
readonly reject: (reason: unknown) => void;
constructor();
}
export {};