Function: timeout-debounce

timeout-debounce is an autoloaded and byte-compiled function defined in timeout.el.gz.

Signature

(timeout-debounce FUNC &optional DELAY DEFAULT)

Documentation

Debounce FUNC by making it run DELAY seconds after it is called.

This advises FUNC, when called (interactively or from code), to
run after DELAY seconds. If FUNC is called again within this time,
the timer is reset.

DELAY defaults to 0.5 seconds. DELAY can be a number, a symbol (whose value is a number), or a function (that evaluates to a number). When passed a symbol or function, it is evaluated at runtime for dynamic duration. Using a delay of 0 removes any debounce advice.

The function returns immediately with value DEFAULT when called the first time. On future invocations, the result from the previous call is returned.

Aliases

timeout-debounce! (obsolete since v2.0)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/timeout.el.gz
;;;###autoload
(defun timeout-debounce (func &optional delay default)
  "Debounce FUNC by making it run DELAY seconds after it is called.

This advises FUNC, when called (interactively or from code), to
run after DELAY seconds.   If FUNC is called again within this time,
the timer is reset.

DELAY defaults to 0.5 seconds.  DELAY can be a number, a symbol (whose
value is a number), or a function (that evaluates to a number).  When
passed a symbol or function, it is evaluated at runtime for dynamic
duration.  Using a delay of 0 removes any debounce advice.

The function returns immediately with value DEFAULT when called the
first time.  On future invocations, the result from the previous call is
returned."
  (if (and delay (eq delay 0))
      (advice-remove func 'debounce)
    (advice-add func :around (timeout--debounce-advice delay default)
                '((name . debounce)
                  (depth . -99)))))