/** * Simple composable factory typeclass */ export interface Provider { get(): Promise; transform(lambda: (x: T) => R | PromiseLike): Provider; } /** * Little lazy singleton provider with memory and mutex * that self-updates on get() after a ttl * expires. * * - if ttl < 0, then the LazyProvider acts as a LazySingleton * - if ttl === 0, then the LazyProvider calls through to the loader * on every call - there is no cache * - if ttl > 0, then the provider does lazy refresh * once the ttl expires */ export declare class LazyProvider implements Provider { private _thing; private reload; private ttlSecs; private _lastLoadTime; private loader; /** * @param loader lambda that loads the thing on demand * @param ttlSecs number of seconds to cache the thing before triggering a reload, * default to never reload (-1) */ constructor(loader: () => T | Promise, ttlSecs?: number); /** * Refresh if ttl expired or force true * @param force * @return cached this.thing and the promise * that loads the new data when reload is done */ refreshIfNecessary(force?: boolean): { current: Promise; next: Promise; }; get(): Promise; /** * Date.now of last load attempt completion - * whether it succeeded or not. Zero until after * the first call to .thing */ get lastLoadTime(): number; /** * Apply a transformation on this thing. * Shortcut for new LazyProvider(() => parent.thing.then(...)) * Note that refresh() on the child thing * does not force a refresh on the parent, and * vice versa, but the child inherits the ttl from * its parent. * * @param lambda */ transform(lambda: (x: T) => R | PromiseLike): LazyProvider; } export declare function singletonProvider(loader: () => T | Promise): Provider; export declare function passThroughProvider(loader: () => T | Promise): Provider; export declare function asFactory(provider: LazyProvider): () => Promise;