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

How to get the buffer size of a channel from clojure/core.async?

我想知道如何在 clojure 中获取通道的大小。 我用 count 试过,但不支持。 Clojure 文档通常很好,但这次我找不到任何相关信息。

示例:

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

我找到了解决方案。

(.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