Clamps Dictionary
speedlim-watch
Function
(speedlim-watch timeout fn)
Call fn whenever a value accessed using get-val in the body of the function is changed, limiting the speed between two consecutive calls to the function to timeout in seconds.
speedlim-watch returns a function to remove the relation, speedlim-watch has established.
Also refer to the chapter cl-refs in the Clamps Packages documentation for additional examples.
Arguments
fn |
Function of no arguments to call |
Note
If the function returnd by speedlim-watch
is called with a
numerical argument, the number in the argument will reset the timeout
of the speedlim and the relation is *not* removed.
Example
(defparameter *my-value* (make-ref 1.0)) (defparameter *unwatch* nil) (progn (unwatch-all *unwatch*) (push (speedlim-watch 1 (lambda () (imsg :warn "value: ~a" (get-val *my-value*)))) *unwatch*)) (loop for i below 400 do (at (+ (now) (* i 0.01)) (lambda () (set-val *my-value* (random 1.0))))) ;;; reset timeout (funcall (first *unwatch*) 0.2) (loop for i below 400 do (at (+ (now) (* i 0.01)) (lambda () (set-val *my-value* (random 1.0)))))