This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-19
Channels
- # adventofcode (36)
- # asami (3)
- # babashka (22)
- # beginners (65)
- # calva (5)
- # clj-kondo (1)
- # cljs-dev (3)
- # clojure-europe (1)
- # clojurescript (3)
- # conjure (1)
- # core-async (6)
- # datomic (3)
- # emacs (4)
- # introduce-yourself (3)
- # juxt (11)
- # lsp (64)
- # malli (10)
- # missionary (11)
- # music (1)
- # off-topic (2)
- # pathom (1)
- # practicalli (1)
- # reagent (6)
- # reitit (3)
- # releases (3)
- # xtdb (9)
does this make sense to you? I have a stream of events and I like to make replies, but I want to throttle by discord channel id. I'm thinking to use pub/sub and ensure the subs somehow (the channel ids are only known at runtime)
ended up with this, probably awful for some reason 😛
(defn
<throttle-by-topic
[<in topic-fn >out]
(let [topic->c (atom {})
ensure-sub (fn
[topic]
(or
(@topic->c topic)
(let [c1 (a/chan (a/sliding-buffer 1))
c (<throttle c1 2000)]
(a/pipe c >out)
(get
(swap! topic->c assoc topic c1)
topic))))]
(a/go-loop
[m (a/<! <in)]
(when-let
[topic (and m (topic-fn m))]
(a/>! (ensure-sub topic) m)
(recur (a/<! <in))))
>out))
i started thinking about your problem, then i started reading this post https://github.com/ptaoussanis/sente/issues/124
i belive zach built a lib around the idea of windowing and backpressure bc he couldn't make core async work the way he needed.
https://github.com/clj-commons/manifold/blob/master/doc/stream.md talks about throttling but i didnt look at the implementation at all.