【问题标题】:core.async toggle channel mixcore.async 切换通道组合
【发布时间】:2016-04-11 20:11:00
【问题描述】:

我正在试验 core.async 的混音。似乎在混音中使输入通道静音将是实现背压的一种可能方式。我正在使用下面的代码:

(def output-chan (chan))
(def input-chan (chan))
(def mixer (admix (mix output-chan) input-chan))
(toggle mixer {input-chan {:mute true}})

评估 REPL 中的最后一行给出

CompilerException java.lang.IllegalArgumentException: No implementation of method: :toggle* of protocol: #'clojure.core.async/Mix found for class: java.lang.Boolean.

上面的示例代码有什么问题?

谢谢!

【问题讨论】:

    标签: clojure core.async backpressure


    【解决方案1】:

    (def 混合器 (admix (mix output-chan) input-chan))

    您将admix 的返回值分配给mixer,这是一个布尔值,而不是预期的混合器。试试:

    (def output-chan (chan))
    (def input-chan (chan))
    (def mixer (mix output-chan))
    (admix mixer input-chan)
    (toggle mixer {input-chan {:mute true}})
    

    【讨论】:

    • 非常感谢!我想我对mixer 的可变性感到困惑。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    • 2015-07-04
    • 1970-01-01
    • 1970-01-01
    • 2015-10-29
    相关资源
    最近更新 更多