UNPKG

@nerjs/batchloader

Version:

`BatchLoader` is a tool for batching data requests with support for deduplication, caching, and parallel task management. It is designed to enhance flexibility and performance in scenarios requiring asynchronous data processing. This module was inspired b

23 lines (22 loc) 816 B
import { DeduplicatorRunnerCallback, IDeduplicatorOptions } from './interfaces'; export declare class Deduplicator<T, R> { private readonly runnerFn; private readonly options; private readonly runners; constructor(runnerFn: DeduplicatorRunnerCallback<T, R>, options: IDeduplicatorOptions<T>); private run; private callError; private clearRunner; private createTimeout; private createRunner; private getOrCreateRunner; /** * @description Adds a query to the execution queue or joins an already running request with the same key. Returns a promise with the result of the task execution. */ call(query: T): Promise<R>; restartTimeout(query: T): void; /** * @description Cancels all active tasks and clears their state. */ clear(): void; }