when I put a msg in a channel, I want that all listeners receive it. It's possible in core-async?
you can use pub and sub
this is done by making a new sub channel per client, because messages still only go to one consumer, so the workaround is defining a channel that gets all the messages that another channel has
I dont need the "topic" stuff, but should work. tnks
I've used pub/sub in production, but I never needed the topic
oh wait - @souenzzo I think you actually want mult
and tap
rather than pub and sub
they are simpler and directly do the thing you want
Is this equivalent?
(go (>! out-ch (<! ch)))
to
(go (pipe ch out-ch))
not quite, pipe will fully consume the input channel
the first example only pulls a single value
(defn pipe
"Takes elements from the from channel and supplies them to the to
channel. By default, the to channel will be closed when the from
channel closes, but can be determined by the close? parameter. Will
stop consuming the from channel if the to channel closes"
([from to] (pipe from to true))
([from to close?]
(go-loop []
(let [v (<! from)]
(if (nil? v)
(when close? (close! to))
(when (>! to v)
(recur)))))
to))
Thanks @ghadi! I’ve bee playing with core.async to ingest large CSV files and queue rows to SQS for later processing
@hiredman Sorry for the delayed response, but I wasn't surprised by the fact that alts! chose a channel with a ready value rather than an unexpired timeout ... what I was surprised by was that if that happens in a loop, it stops any timeouts in the system from ever triggering or making progress, for all eternity, until you stop alts!-ing on the promise chan. That is down to an implementation detail, and even in a single-threaded system, it doesn't need to be implemented or behave that way.
ah yeah, that is a bummer
Anyway thanks a lot for your help and insight!