summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarthik Chikmagalur <karthikchikmagalur@gmail.com>2025-08-30 01:12:41 -0700
committerKarthik Chikmagalur <karthikchikmagalur@gmail.com>2025-08-30 01:12:41 -0700
commit4b06e62d060f658f2b90f2282d320a47de2f6077 (patch)
tree92596da323ade602968bb7940e9efeae3be54b5e
parent550258bb551783d8238e5d958668b773aed3e13c (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.el29
1 files changed, 14 insertions, 15 deletions
diff --git a/timeout.el b/timeout.el
index 57c7e62..a708b04 100644
--- a/timeout.el
+++ b/timeout.el
@@ -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)