This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-05-02
Channels
- # announcements (2)
- # babashka (9)
- # calva (8)
- # cider (2)
- # clj-kondo (3)
- # clojure (113)
- # clojure-austin (1)
- # clojure-dev (27)
- # clojure-europe (11)
- # clojure-germany (2)
- # clojure-losangeles (1)
- # clojure-nl (1)
- # clojure-norway (18)
- # clojure-uk (32)
- # clojuredesign-podcast (4)
- # core-async (16)
- # core-typed (45)
- # cursive (5)
- # data-science (1)
- # datomic (7)
- # events (1)
- # gratitude (2)
- # hugsql (1)
- # hyperfiddle (7)
- # integrant (4)
- # keechma (10)
- # leiningen (4)
- # malli (1)
- # missionary (14)
- # off-topic (62)
- # onyx (8)
- # other-languages (21)
- # pathom (1)
- # reitit (4)
- # releases (2)
- # shadow-cljs (35)
- # squint (1)
- # transit (1)
Is there a way to send a signal between go-blocks or threads? I know the typical communication piece is a channel, but for what I am thinking I am not sure that can work. Suppose you have the following go block:
(go
(loop [next-item (
If I use a separate queue to signal the end of the processing loop, I'll have to park waiting for a signal on each loop, which is not what I want (there may be only one signal). I can't end the channel, because it may have an arbitrary number of consumers, not all of whom should be ending. I can use an atom, but I am looking to see if there's a way to do it without holding stateIf I understand correctly, This is what a/alt!
is for
(go
(loop []
(a/alt!
c ([next-item] (process next-item) (recur))
signal-tripped-ch :end)))
> I can't end the channel, because it may have an arbitrary number of consumers, not all of whom should be ending
Don't mean to make more work for you, but multiple consumers and multiple producers are an anti pattern, you should use merge and tap
Can you expand on that? I usually use mult
.
For example, I commonly work with streams from LLM outputs represented as channels. I typically use mult
to split the channel in 2, one going to the client over SSE, and the other going to a reducer that posts the reduced output to a database.
For the use case for which I asked about tap
, I have a channel of data coming in from the client over websockets. Outputs from an ML streaming algorithm trigger certain async processes to either happen or stop, but I don't want to stop the data coming in from the socket, which has a lot of listeners on it
hard disagree about multiple consumers and producers being an antipattern, merge is convenient in many cases, but merge runs a normal go loop doing a copy and the behavior of doing multiple takes via alts your self vs. the indirection of merge doing it and presenting results over a channel are different.
It's a very opinionated anti pattern (and I was Wong about tap there) but I find multiple processes producing to multiple channels which are merged cleaner than multiple producers to same channel, buys you the overhead of clean shutdown
@alexmiller I just noticed https://clojure.atlassian.net/browse/ASYNC-209 is closed because I had some code that on review was calling >!
outside of a go block, and I knew there was an issue that would have turned that into a compile time error(macro expand time) instead of a runtime error. Having just tripped over this issue, it is a real bummer to see the ticket is both closed as a wontfix and has 0 commentary about why.
I can reopen it, don't remember why