Fork me on GitHub
#core-async
<
2019-06-06
>
souenzzo01:06:09

when I put a msg in a channel, I want that all listeners receive it. It's possible in core-async?

noisesmith01:06:28

you can use pub and sub

noisesmith01:06:47

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

souenzzo01:06:54

I dont need the "topic" stuff, but should work. tnks

noisesmith01:06:52

I've used pub/sub in production, but I never needed the topic

noisesmith01:06:50

oh wait - @souenzzo I think you actually want mult and tap rather than pub and sub

noisesmith01:06:23

they are simpler and directly do the thing you want

jplaza01:06:20

Is this equivalent?

(go (>! out-ch (<! ch)))
to
(go (pipe ch out-ch))

ghadi01:06:02

not quite, pipe will fully consume the input channel

ghadi01:06:21

the first example only pulls a single value

ghadi01:06:29

(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))

jplaza01:06:16

Thanks @ghadi! I’ve bee playing with core.async to ingest large CSV files and queue rows to SQS for later processing

pmooser15:06:54

@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.

hiredman16:06:36

ah yeah, that is a bummer

pmooser16:06:15

Anyway thanks a lot for your help and insight!