user3139545
user3139545

Reputation: 7394

mult vs broadcast in core.async

Im playing around with core.async and find it very fun to work with. However I fail at understanding what are the different use cases for mult and broadcast. Are they both needed or will one be replaced by the other? So far the only difference i have found is that it is easier to tap in and untag with mult. Not sure how to unsubscribe from a broadcast, is this the only difference?

Below I have an example showing how to solve a problem using both methods.

;; Using mult with tap
(def in (chan))
(def multiple (mult in))

(def out-1 (chan))
(tap multiple out-1)

(def out-2 (chan))
(tap multiple out-2)

(go (>! in "PutIN"))

(go (prn "From out-1: " (<! out-1)))
(go (prn "From out-2: " (<! out-2)))

//

;; Using broadcast
(def bout-1 (chan))
(def bout-2 (chan))
(def broadcast-in (broadcast bout-1 bout-2))

(go (>! broadcast-in "PutINBroadcast"))
(go (prn "From bout-1: " (<! bout-1)))
(go (prn "From bout-2: " (<! bout-2)))

Upvotes: 3

Views: 990

Answers (1)

Leon Grapenthin
Leon Grapenthin

Reputation: 9276

This is the note to the clojure.core.async.lab namespace with broadcast.

core.async HIGHLY EXPERIMENTAL feature exploration

Caveats:

  1. Everything defined in this namespace is experimental, and subject to change or deletion without warning.

  2. Many features provided by this namespace are highly coupled to implementation details of core.async. Potential features which operate at higher levels of abstraction are suitable for inclusion in the examples.

  3. Features provided by this namespace MAY be promoted to clojure.core.async at a later point in time, but there is no guarantee any of them will.

Nobody has worked on it for a long time now, it has never been ported to ClojureScript. I'd expect it to be removed from core.async in the near future. mult is the later development.

Upvotes: 6

Related Questions