diff options
| author | Karthik Chikmagalur <karthikchikmagalur@gmail.com> | 2025-08-30 01:12:41 -0700 |
|---|---|---|
| committer | Karthik Chikmagalur <karthikchikmagalur@gmail.com> | 2025-08-30 01:12:41 -0700 |
| commit | 4b06e62d060f658f2b90f2282d320a47de2f6077 (patch) | |
| tree | 92596da323ade602968bb7940e9efeae3be54b5e | |
| parent | 550258bb551783d8238e5d958668b773aed3e13c (diff) | |
timeout: Remove DEFAULT argument for throttle functions
* timeout.el (timeout--throttle-advice, timeout-throttle!,
timeout-throttle): Remove the DEFAULT argument to the throttle
functions. This is never used, since the result from the current
call or the previous successful call is always available for a
throttled function.
| -rw-r--r-- | timeout.el | 29 |
1 files changed, 14 insertions, 15 deletions
@@ -51,17 +51,18 @@ ;;; Code: (require 'nadvice) -(defun timeout--throttle-advice (&optional timeout default) +(defun timeout--throttle-advice (&optional timeout) "Return a function that throttles its argument function. -TIMEOUT defaults to 1 second. The function returns immediately with -value DEFAULT when called the first time. On future invocations, the -result from the previous call is returned. +TIMEOUT defaults to 1 second. + +When FUNC does not run because of the throttle, the result from the +previous successful call is returned. This is intended for use as function advice." (let ((throttle-timer) (timeout (or timeout 1.0)) - (result default)) + (result)) (lambda (orig-fn &rest args) "Throttle calls to this function." (prog1 result @@ -123,33 +124,31 @@ returned." (depth . -99))))) ;;;###autoload -(defun timeout-throttle! (func &optional throttle default) +(defun timeout-throttle! (func &optional throttle) "Make FUNC run no more frequently than once every THROTTLE seconds. THROTTLE defaults to 1 second. Using a throttle of 0 removes any throttle advice. -The function returns immediately with value DEFAULT when called the -first time. On future invocations, the result from the previous call is -returned." +When FUNC does not run because of the throttle, the result from the +previous successful call is returned." (if (and throttle (= throttle 0)) (advice-remove func 'throttle) - (advice-add func :around (timeout--throttle-advice throttle default) + (advice-add func :around (timeout--throttle-advice throttle) '((name . throttle) (depth . -98))))) -(defun timeout-throttle (func &optional throttle default) +(defun timeout-throttle (func &optional throttle) "Return a throttled version of function FUNC. The throttled function runs no more frequently than once every THROTTLE seconds. THROTTLE defaults to 1 second. -The function returns immediately with value DEFAULT when called the -first time. On future invocations, the result from the previous call is -returned." +When FUNC does not run because of the throttle, the result from the +previous successful call is returned." (let ((throttle-timer nil) (throttle (or throttle 1)) - (result default)) + (result)) (if (commandp func) ;; INTERACTIVE version (lambda (&rest args) |
