Files
v10/dist/function/throttle.d.ts

30 lines
1.3 KiB
TypeScript

//#region src/function/throttle.d.ts
/** A throttled function that can be cancelled. */
interface Throttled<Args extends unknown[]> {
(...args: Args): void;
/** Cancel any pending trailing-edge invocation. */
cancel(): void;
}
interface ThrottleOptions {
/**
* When `true`, the first call invokes `fn` immediately (leading edge) and
* starts the cooldown window. Calls during cooldown are coalesced and fire
* on the trailing edge. If no calls arrive during the window the next call
* is treated as a fresh leading invocation.
*/
leading?: boolean;
}
/**
* Throttle: limits `fn` to at most once per `ms` window.
*
* - Default (no options): trailing-edge only — the first call schedules a
* timer; subsequent calls within the window update the arguments. The
* function fires once per window with the latest arguments.
* - `{ leading: true }`: leading + trailing — the first call invokes
* immediately and opens a cooldown window. Subsequent calls within the
* window are coalesced to a single trailing-edge invocation.
*/
declare function throttle<Args extends unknown[]>(fn: (...args: Args) => void, ms: number, options?: ThrottleOptions): Throttled<Args>;
//#endregion
export { ThrottleOptions, Throttled, throttle };
//# sourceMappingURL=throttle.d.ts.map