import { debounce } from 'lodash-es'; export interface BatchedDebounce { (item: T): Promise; cancel: () => void; } type BatchCallback = (items: T[]) => R extends void ? Promise | void : Promise | R[]; /** * Creates a debounced function that batches multiple individual calls into a single batch operation. * Each call returns a promise that resolves with the corresponding result from the batch callback. * * @template T - The type of input items * @template R - The type of result items (use void for callbacks that don't return results) * * @param callback - Function that processes a batch of items. Should return an array with the same * length as the input array, or void if no results are needed. * @param wait - The number of milliseconds to delay before processing the batch * @param options - Optional debounce options (leading, trailing, maxWait) passed to lodash debounce * * @returns A debounced function that accepts individual items and returns promises for their results. * The function includes a `cancel()` method to cancel pending batches. * * @example * ```typescript * // With results * const batchedFetch = batchedDebounce( * async (ids: number[]) => { * const response = await fetch('/api/items', { * method: 'POST', * body: JSON.stringify({ ids }) * }); * return response.json(); * }, * 100 * ); * * const item1 = batchedFetch(1); * const item2 = batchedFetch(2); * const results = await Promise.all([item1, item2]); * * // Without results (void) * const batchedLog = batchedDebounce( * async (ids: number[]) => { * await fetch('/api/log', { * method: 'POST', * body: JSON.stringify({ ids }) * }); * }, * 100 * ); * * await batchedLog(1); * ``` */ export declare function batchedDebounce(callback: BatchCallback, wait: number, options?: Parameters[2]): BatchedDebounce; export {};