如何从clojure / core.async中获取通道的缓冲区大小?

时间:2016-12-09 18:24:06

标签: concurrency clojure leiningen core.async

我想知道如何在clojure中获得频道的大小。 我尝试了计数,但它不受支持。 Clojure文档通常很好,但这次我找不到任何关于它的东西。

示例:

(def channel1 (chan 3))
(println(count channel1))
Should be 3 but  throws  "count not supported on this type: ManyToManyChannel"

1 个答案:

答案 0 :(得分:5)

我找到了解决方案。

(.buf (.buf ch)) ;; Get elements in buffer
;; => (:chan :on :elements)

(.count (.buf ch)) ;; Get number of elements in buffer
;; => 3

(.n (.buf ch)) ;; Get size of buffer
;; => 10

(.full? (.buf mychan)) ;; Is buffer full?
;; => false

进一步阅读here