There is a implementation of "broadcast" in core.async? I mean, when I put into a channel, all listeners will receive the message
(let [pub-port (async/chan)
pub (async/pub pub-port (constantly ::all))
sub-port (async/chan)
sub (async/sub pub ::all sub-port)]
(async/go
(prn [1 (async/<! sub)]))
(async/go
(prn [2 (async/<! sub)]))
(async/put! pub-port "hello"))
On this example, just 1 or 2 will be printed. I want both.Mults
You can have a pub and a mult and tap a channel to both
There is no examples of use of mult
@hiredman
I tryied in this way
(let [pub-port (async/chan)
mult (async/mult pub-port)
sub-port (async/chan)]
(async/tap mult sub-port)
(async/go
(prn [1 (async/<! sub-port)]))
(async/go
(prn [2 (async/<! sub-port)]))
(async/put! pub-port "ok"))
With the same result of pub/sub
Looking for this: https://github.com/clojure/core.async/blob/master/src/test/cljs/cljs/core/async/tests.cljs#L263 My solution looks right.
I think I get it. I need to create a new channel and tap it.
(letfn [(listen [m]
(let [c (async/chan)]
(async/tap m c)
c))]
(let [pub-port (async/chan)
mult (async/mult pub-port)]
(async/go
(let [c (listen mult)]
(prn [1 (async/<! c)])))
(async/go
(let [c (listen mult)]
(prn [2 (async/<! c)])))
(async/go
(async/>! pub-port "ok"))))
This listen
function make sense? It's implemented somewhere?@souenzzo also look at (promise-chan)
That is, if you need to put one, and only one value on the channel and have all potential consumers receive that value