Debouncer
-
class
ui.Debouncer() A utility class that delays the execution of a callback function until after a specified delay period has elapsed since the last time it was invoked. This is useful for optimizing performance by limiting the rate at which a function executes, such as handling rapid user input events.
The debouncer returns a Promise that resolves with the callback’s return value or rejects if the callback throws an error or if the debounced call is cancelled.
Constructors
-
ui.Debouncer.constructor() - Debouncer(callback: (args: TArgs) => TReturn):
Debouncer<TArgs, TReturn>Creates a new Debouncer instance with the specified callback function.
Parameters
callback: (args: TArgs) => TReturn
The function to debounce. Can be synchronous or asynchronous.Returns:
Debouncer<TArgs, TReturn>
Properties
-
ui.Debouncer.callback - callback: (args: TArgs) => TReturn
The callback function to be executed after the debounce delay. This can be updated dynamically to change the debounced behavior.
Accessors
-
ui.Debouncer.isPending() - get isPending(): boolean
Indicates whether a debounced callback is currently waiting to execute.
Returns: boolean
trueif a callback is scheduled to execute,falseotherwise
Methods
-
ui.Debouncer.clear() - clear(): void
Cancels any pending debounced execution. If a debounced callback is waiting to execute, it will be cancelled and the associated Promise will reject with no error.
This method is safe to call multiple times and can be called even when no execution is pending.
Returns: void
-
ui.Debouncer.debounce() - debounce(delay: number, args: TArgs): Promise
Schedules the callback to execute after the specified delay. If called again before the delay elapses, the previous call is cancelled and a new delay period begins.
Parameters
delay: number
The number of milliseconds to wait before executing the callbackargs: TArgs
Arguments to pass to the callback functionReturns: Promise
A Promise that resolves with the callback’s return value or rejects if:- The callback throws an error
- The debounced call is cancelled via
clear()or anotherdebounce()call