Fork me on GitHub
#clojurescript
<
2024-05-06
>
James Pratt12:05:24

I'm having an issue with closure's google.functions throttle or rateLimit function I wonder if anyone here can throw light on it? Neither of the functions seems to be limiting calls to the enclosed function! https://github.com/submergedstructure/transcript-editor/blob/main/src/com/submerged_structure/ui.cljs#L96 My code is part of a fulcro project but I guess this is a problem with my calling of the google functions. I have an event handler for an audio player that is being called for I think every sample played in the audio player and I want to limit calls to the enclosed function that are overwhelming fulcro's state management machinery.

James Pratt12:05:36

the compiled app is up here to poke at: https://dev.submergedstructure.com/

James Pratt12:05:41

here's what happens when you press play:

James Pratt12:05:59

seems like even google.functions/rateLimit either is being overwhelmed by the calls to it or I am calling separate instances of the function and the timing is separate for each call.

thheller12:05:41

you need to hold a reference to the returned function and call that

thheller12:05:31

(def update-current-word-rate-limited
  (gf/rateLimit update-current-word 1000))

thheller12:05:05

then just (update-current-word-rate-limited this id t)

👍 1
thheller12:05:39

the way you have it you are re-creating the wrapping function every time, so all state it keeps to do the rate limiting thing is also re-created with every call

Adam Kalisz13:05:23

Reposting from cljs-dev: Hi, I have won tickets to JS nation (https://jsnation.com/) and React summit (https://reactsummit.com/) in Amsterdam in the middle of June. I am not able to go but perhaps somebody might be interested. I would like to give for free the tickets ideally to somebody, who has done a bit of development in the open source ClojureScript community. Please send me a DM, if you are interested or know about somebody, for whom this would be highly interesting.

🚀 3