【问题标题】:mult vs broadcast in core.async多与 core.async 中的广播
【发布时间】:2015-04-11 16:01:43
【问题描述】:

我在玩 core.async,发现它非常有趣。但是,我无法理解 mult 和广播的不同用例是什么。它们都需要还是会被另一个替换? 到目前为止,我发现的唯一区别是使用 mult 更容易点击和取消标记。不知道如何取消订阅广播,这是唯一的区别吗?

下面我有一个例子展示了如何使用这两种方法来解决问题。

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

【问题讨论】:

    标签: clojure clojurescript core.async


    【解决方案1】:

    这是clojure.core.async.lab 命名空间与broadcast 的注释。

    core.async 高度实验性的功能探索

    注意事项:

    1. 此命名空间中定义的所有内容都是实验性的,如有更改或删除,恕不另行通知。

    2. 此命名空间提供的许多功能都与 core.async 的实现细节高度耦合。运行的潜在功能 在更高的抽象层次上适合包含在 例子。

    3. 此命名空间提供的功能可能会在以后升级为 clojure.core.async,但不能保证 他们中的任何一个都会。

    现在没有人研究它很长时间了,它从未被移植到 ClojureScript。我希望它会在不久的将来从 core.async 中删除。 mult是后期开发的。

    【讨论】:

      猜你喜欢
      • 2012-07-18
      • 1970-01-01
      • 2019-09-03
      • 2012-01-23
      • 2013-05-21
      • 2016-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多