Function: consult--async-throttle
consult--async-throttle is a byte-compiled function defined in
consult.el.
Signature
(consult--async-throttle &optional THROTTLE DEBOUNCE)
Documentation
Async function which throttles input.
The THROTTLE delay defaults to consult-async-input-throttle.
The DEBOUNCE delay defaults to consult-async-input-debounce.
Source Code
;; Defined in ~/.emacs.d/elpa/consult-20260805.1130/consult.el
(defun consult--async-throttle (&optional throttle debounce)
"Async function which throttles input.
The THROTTLE delay defaults to `consult-async-input-throttle'.
The DEBOUNCE delay defaults to `consult-async-input-debounce'."
(setq throttle (or throttle consult-async-input-throttle)
debounce (or debounce consult-async-input-debounce))
(lambda (sink)
(let ((timer (timer-create)) (last 0) initial-p input)
(lambda (action)
(pcase action
((pred stringp)
(unless (equal action input)
(cancel-timer timer)
(funcall sink 'cancel)
(timer-set-function timer (lambda ()
(setq last (float-time))
(funcall sink action)))
(timer-set-time
timer
(timer-relative-time
;; Debounce only if the user entered new input. Start
;; immediately if the minibuffer contains initial input.
nil (max (if (funcall initial-p) 0 debounce)
(- (+ last throttle) (float-time)))))
(setq input action)
(timer-activate timer))
nil)
('setup
(setq initial-p
(consult--in-buffer
(let ((initial (minibuffer-contents-no-properties)))
(lambda ()
(equal initial (minibuffer-contents-no-properties))))))
(funcall sink action))
((or 'cancel 'destroy)
(cancel-timer timer)
(funcall sink action))
(_ (funcall sink action)))))))