当同时将大量通道添加到组合通道时,会抛出此错误
{{java.lang.AssertionError: Assert failed: A single channel cannot have more than 1024 pending puts. Please consider using a windowed buffer.}}
我们可以在REPL中使用以下代码复现此问题
user> (require '[clojure.core.async :as a])
nil
user> (defn mixtest []
(let [out (a/chan 1024)
mix (a/mix out)]
(dotimes [i 2048]
(let [chan (a/chan)]
(a/admix mix chan)
(a/put! chan i)))))
(mixtest)
#'user/mixtestAssertionError Assert failed: A single channel cannot have more than 1024 pending puts. Please consider using a windowed buffer.
(< (.size puts) impl/MAX-QUEUE-SIZE) clojure.core.async.impl.channels.ManyManyChannel (channels.clj:150)
user>
这是混合实现中使用未缓冲通道的结果。由于通道的功能只是更新组合的内部数据结构,所以使用带窗口的缓冲通道似乎可以解决此问题。补丁0001-Change-channel-to-sliding-buffer.patch包含提议的解决方案。