seitu
Version:
29 lines • 1.19 kB
text/typescript
import { i as Subscribable, n as Readable } from "./index-B0IeflOl.mjs";
//#region src/core/throttled-fn/index.d.ts
interface ThrottledFn<F extends (...args: any[]) => any> extends Readable<ReturnType<F> | undefined>, Subscribable<ReturnType<F> | undefined> {
(...args: Parameters<F>): void;
/** Drop the pending trailing call and reset the throttle window. */
cancel: () => void;
/** Run the pending trailing call now and reset the window. No-op if nothing is pending. */
flush: () => void;
pending: () => boolean;
}
/**
* Throttled callable that is also a subscribable. First call fires immediately;
* later calls within `wait` batch into one trailing call.
*
* @example
* ```ts twoslash
* import { createThrottledFn } from 'seitu'
*
* const log = createThrottledFn((msg: string) => console.log(msg), 300)
* log.subscribe(result => console.log('result:', result))
* log('hello') // fires immediately
* log('world') // throttled — fires after 300ms
* log.get()
* log.flush()
* ```
*/
declare function createThrottledFn<F extends (...args: any[]) => any>(fn: F, wait: number): ThrottledFn<F>;
//#endregion
export { createThrottledFn as n, ThrottledFn as t };