简体   繁体   English

core.async中的mult vs broadcast

[英]mult vs broadcast in core.async

Im playing around with core.async and find it very fun to work with. 我正在玩core.async并发现它非常有趣。 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. 到目前为止,我发现的唯一区别是,使用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)))

This is the note to the clojure.core.async.lab namespace with broadcast . 这是带有broadcastclojure.core.async.lab命名空间的注释。

core.async HIGHLY EXPERIMENTAL feature exploration core.async高度实验性的特征探索

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. 此命名空间提供的许多功能都与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. 此命名空间提供的功能可能会在以后的某个时间点提升为clojure.core.async,但不能保证它们中的任何一个。

Nobody has worked on it for a long time now, it has never been ported to ClojureScript. 很长一段时间没有人研究它,它从未被移植到ClojureScript。 I'd expect it to be removed from core.async in the near future. 我希望它在不久的将来会从core.async中删除。 mult is the later development. mult是后来的发展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM