UNPKG

@easy-sync/batching

Version:
26 lines (22 loc) 1.21 kB
/** * Scheduler that waits for a quiet period (debounce) with a maximum wait time. * It waits for `delayMs` since the last request, but will trigger no later than `maxWaitMs` after the first request. * If a maxBatchSize is provided and the batch size reaches that size, it triggers immediately. * * @param delayMs - The delay in milliseconds. * @param maxWaitMs - The maximum wait time in milliseconds. * @param maxBatchSize - The maximum batch size. * @returns The scheduler function. */ export declare function createDebouncedScheduler(delayMs: number, maxWaitMs: number, maxBatchSize?: number): Scheduler; /** * Scheduler that batches all requests within a fixed time window (from the first request). * If a maxBatchSize is provided and the batch size reaches that size, it triggers immediately. * @param windowMs - The time window in milliseconds. * @param maxBatchSize - The maximum batch size. * * @returns The scheduler function. */ export declare function createFixedWindowScheduler(windowMs: number, maxBatchSize?: number): Scheduler; export declare type Scheduler = (firstRequestTime: number, lastRequestTime: number, batchSize: number) => number; export { }