(defunmake-debouncer(delay-in-secondscallback);; TODO there's probably a bunch of race conditions...(let((last-time)(thread)(saved-args))(labels((now()(/(get-internal-real-time)#.(floatinternal-time-units-per-second)))(update-last-time(now)(setflast-timenow))(overduep(now)(andlast-time(<=delay-in-seconds(-nowlast-time))))(actually-call(nowargs)(update-last-timenow)(setfthreadnil)(applycallbackargs))(wait-loop()(loop:fornow=(now):until(overduepnow):do(let((delay(max0.025(-(+last-timedelay-in-seconds)now))))#++(progn(format*debug-io*"~&About to sleep ~s seconds"delay)(force-output*debug-io*))(sleepdelay)))(actually-call(now)saved-args))(maybe-funcall(&restargs)(update-last-time(now))(setfsaved-argsargs)(unlessthread(setfthread(bt:make-thread#'wait-loop:name"Debouncer thread")))last-time))#'maybe-funcall)))
no macro \o/
A single thread waits a minimum amount of time, in the meantime the arguments given from the user are updated.
reminder: labels is like let but to create local functions.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here's another version: gitlab.com/fstamour/cache-cache/-/...
no macro \o/
A single thread waits a minimum amount of time, in the meantime the arguments given from the user are updated.
reminder:
labelsis likeletbut to create local functions.