This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-15
Channels
- # announcements (10)
- # asami (5)
- # babashka (49)
- # babashka-sci-dev (8)
- # beginners (25)
- # calva (98)
- # cider (2)
- # clj-kondo (22)
- # clojure (32)
- # clojure-dev (12)
- # clojure-europe (32)
- # clojure-nl (3)
- # clojure-spec (3)
- # clojure-uk (10)
- # clojurescript (12)
- # community-development (1)
- # conjure (71)
- # cursive (7)
- # datalog (6)
- # events (2)
- # figwheel-main (2)
- # fulcro (4)
- # jobs (2)
- # kaocha (3)
- # lsp (43)
- # membrane (12)
- # missionary (9)
- # off-topic (61)
- # pathom (7)
- # polylith (2)
- # reagent (38)
- # remote-jobs (4)
- # shadow-cljs (17)
- # specter (1)
- # tools-deps (38)
- # vim (51)
- # web-security (5)
how to write a limiter idiomatically? i would like to limit the number of requests to the api in a unit of time but my functional thinking is not yet the best...
I have come up with something like this for now, but this internal state can probably be cut out somehow
(defn -limit
[n ms >f]
(mi/ap
(let [start-time_ (volatile! (ex/-now-udt))
[i x] (mi/?> (mi/eduction (map-indexed vector) >f))]
(if (zero? (mod (inc i) n))
(do (mi/? (mi/sleep (max 0 (- ms (- (ex/-now-udt) @start-time_))))) (vreset! start-time_ (ex/-now-udt)) x)
x))))