import type { AnyAsyncFunction, AnyFunction } from '../types.js'; export declare function _debounce(func: T, wait: number, opt?: DebounceOptions): T & Cancelable; export declare function _throttle(func: T, wait: number, opt?: ThrottleOptions): T & Cancelable; /** * Like `_debounce`, but for async functions. * * Unlike `_debounce` (which returns a stale `result`/`undefined` for suppressed calls), * `_asyncDebounce` always returns a real Promise, resolving with the coalesced invocation's result. * * @experimental */ export declare function _asyncDebounce(func: T, wait: number, opt?: AsyncDebounceOptions): AsyncDebounced; /** * Like `_throttle`, but for async functions. See `_asyncDebounce` for the Promise semantics. * * @experimental */ export declare function _asyncThrottle(func: T, wait: number, opt?: AsyncThrottleOptions): AsyncDebounced; export interface Cancelable { cancel: () => void; flush: () => void; } /** * Like `Cancelable`, but for the async debounced functions: `flush()` resolves with the flushed * invocation's result (or `undefined` if nothing was pending), and `pending()` is exposed. */ export interface AsyncCancelable { cancel: () => void; flush: () => Promise; pending: () => boolean; } export interface ThrottleOptions { /** * Invoke on the leading edge of the window (immediately, on the first call). * * @default true */ leading?: boolean; /** * Invoke on the trailing edge of the window (after `wait` has elapsed). * * @default true */ trailing?: boolean; } export interface DebounceOptions { /** * Invoke on the leading edge of the window (immediately, on the first call). * * @default false */ leading?: boolean; /** * Invoke on the trailing edge of the window (after `wait` has elapsed). * * @default true */ trailing?: boolean; /** * Maximum time `func` is allowed to be delayed before it's forcibly invoked. */ maxWait?: number; } export interface AsyncThrottleOptions { /** * Invoke on the leading edge of the window (immediately, on the first call). * * @default true */ leading?: boolean; /** * Invoke on the trailing edge of the window (after `wait` has elapsed). * * When `false`, calls dropped within the window (not served by a leading invocation) resolve * with `undefined`. There's no invocation for them to await. This is why the returned function * can resolve with `undefined` even though the original function's return type doesn't express that. * * @default true */ trailing?: boolean; } export interface AsyncDebounceOptions extends AsyncThrottleOptions { /** * Invoke on the leading edge of the window (immediately, on the first call). * * @default false */ leading?: boolean; /** * Maximum time `func` is allowed to be delayed before it's forcibly invoked. */ maxWait?: number; } /** * The function returned by `_asyncDebounce`/`_asyncThrottle`. Same signature as `T`, but resolves * `Awaited> | undefined` * * This is because some configurations (e.g. `trailing: false`) may drop calls without invoking * the original function, so there's no result to await. */ export type AsyncDebounced = ((this: ThisParameterType, ...args: Parameters) => Promise> | undefined>) & AsyncCancelable>>;