
#########
Debouncer
#########

.. js: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.
   
   
   Index
   =====
   
   .. rubric:: Constructors
   
   
   .. rst-class:: api-xref-list
   
   
   * :js:func:`~ui.Debouncer.constructor`
   
   .. rubric:: Properties
   
   
   .. rst-class:: api-xref-list
   
   
   * :js:data:`~ui.Debouncer.callback`
   
   .. rubric:: Accessors
   
   
   .. rst-class:: api-xref-list
   
   
   * :js:func:`~ui.Debouncer.isPending`
   
   .. rubric:: Methods
   
   
   .. rst-class:: api-xref-list
   
   
   * :js:meth:`~ui.Debouncer.clear`
   * :js:meth:`~ui.Debouncer.debounce`
   
   



.. rst-class:: kind-group kind-constructors

.. rubric:: Constructors
   :class: kind-group-title


.. js:method:: ui.Debouncer.constructor

      .. rst-class:: sig-pretty-signature
      
         | Debouncer(**callback**\ : (**args**\ : TArgs) => TReturn): :js:class:`Debouncer <ui.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**\ : :js:class:`Debouncer <ui.Debouncer>`\ <TArgs, TReturn>
      



.. rst-class:: kind-group kind-properties

.. rubric:: Properties
   :class: kind-group-title


.. js:data:: ui.Debouncer.callback

      .. rst-class:: sig-pretty-signature
      
         | callback: (**args**\ : TArgs) => TReturn
      
      The callback function to be executed after the debounce delay. This can be updated dynamically to change the debounced behavior.
      



.. rst-class:: kind-group kind-accessors

.. rubric:: Accessors
   :class: kind-group-title


.. js:method:: ui.Debouncer.isPending

      .. rst-class:: sig-pretty-signature
      
         | *get* isPending(): *boolean*
      
      Indicates whether a debounced callback is currently waiting to execute.
      
      **Returns**\ : *boolean*
      
      
         ``true`` if a callback is scheduled to execute, ``false`` otherwise
      
      



.. rst-class:: kind-group kind-methods

.. rubric:: Methods
   :class: kind-group-title


.. js:method:: ui.Debouncer.clear

      .. rst-class:: sig-pretty-signature
      
         | 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*
      



.. js:method:: ui.Debouncer.debounce

      .. rst-class:: sig-pretty-signature
      
         | 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 callback
      
      
         **args**\ : TArgs
      
      
            Arguments to pass to the callback function
      
      
      
      **Returns**\ : *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 another ``debounce()`` call
      
      




