branch: externals/timeout
commit a5e661de4d3c1d5ac25c449011fe99059fc55920
Author: Karthik Chikmagalur <[email protected]>
Commit: Karthik Chikmagalur <[email protected]>
timeout: Evaluate result on first call to throttled func
* timeout.el (timeout--throttle-advice, timeout-throttled-func):
Capture the correct return value the first time a throttled
function is called. Previously, it would return nil on the very
first call.
This fix was provided by Juri Linkov.
---
timeout.el | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/timeout.el b/timeout.el
index bb6583c4c8..bb27569bfa 100644
--- a/timeout.el
+++ b/timeout.el
@@ -85,7 +85,7 @@ This is intended for use as function advice."
(result))
(lambda (orig-fn &rest args)
"Throttle calls to this function."
- (prog1 result
+ (progn
(unless (and throttle-timer (timerp throttle-timer))
(setq result (apply orig-fn args))
(setq throttle-timer
@@ -93,7 +93,8 @@ This is intended for use as function advice."
(timeout--eval-value timeout-value) nil
(lambda ()
(cancel-timer throttle-timer)
- (setq throttle-timer nil)))))))))
+ (setq throttle-timer nil)))))
+ result))))
(defun timeout--debounce-advice (&optional delay default)
"Return a function that debounces its argument function.
@@ -187,7 +188,7 @@ previous successful call is returned."
"\n\nThrottle calls to this function"))
(interactive (advice-eval-interactive-spec
(cadr (interactive-form func))))
- (prog1 result
+ (progn
(unless (and throttle-timer (timerp throttle-timer))
(setq result (apply func args))
(setq throttle-timer
@@ -195,14 +196,15 @@ previous successful call is returned."
(timeout--eval-value throttle-value) nil
(lambda ()
(cancel-timer throttle-timer)
- (setq throttle-timer nil)))))))
+ (setq throttle-timer nil)))))
+ result))
;; NON-INTERACTIVE version
(lambda (&rest args)
(:documentation
(concat
(documentation func)
"\n\nThrottle calls to this function"))
- (prog1 result
+ (progn
(unless (and throttle-timer (timerp throttle-timer))
(setq result (apply func args))
(setq throttle-timer
@@ -210,7 +212,8 @@ previous successful call is returned."
(timeout--eval-value throttle-value) nil
(lambda ()
(cancel-timer throttle-timer)
- (setq throttle-timer nil))))))))))
+ (setq throttle-timer nil)))))
+ result)))))
(defun timeout-debounced-func (func &optional delay default)
"Return a debounced version of function FUNC.