platform-bible-utils
    Preparing search index...

    Type Alias DebouncedFunction<TFunc>

    DebouncedFunction: (...args: Parameters<TFunc>) => Promise<ReturnType<TFunc>> & {
        cancel: () => void;
        flush: () => Promise<ReturnType<TFunc>> | undefined;
    }

    A debounced function with cancel and flush methods to abandon or immediately run any pending invocation (lodash-style lifecycle controls).

    Type Parameters

    • TFunc extends (...args: any[]) => any

      The type of the function being debounced.

    Type declaration

      • (...args: Parameters<TFunc>): Promise<ReturnType<TFunc>>
      • Parameters

        • ...args: Parameters<TFunc>

        Returns Promise<ReturnType<TFunc>>

    • cancel: () => void

      Cancel any pending debounced invocation. The promise returned by the most recent call rejects with an error whose message is DEBOUNCE_CANCELED_ERROR_MESSAGE.

      IMPORTANT: because cancellation rejects that promise, every call whose result you might later cancel MUST handle its rejection (await in a try/catch, or attach a .catch, filtering on DEBOUNCE_CANCELED_ERROR_MESSAGE to distinguish cancellation from a real error). Fire-and-forget callers that ignore the returned promise will get an unhandled promise rejection when cancel() runs.

    • flush: () => Promise<ReturnType<TFunc>> | undefined

      Run the pending debounced invocation NOW (synchronously, with the most recently passed arguments) instead of waiting out the remaining delay, and clear the timer so it does not fire a second time.

      Useful at lifecycle boundaries where the trailing window would otherwise lose the final invocation (unmount, blur, pagehide) or run it against changed context (see the platform-scripture-editor extension's debounced PDP save).