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

PIN*_*INK 3 concurrency clojure leiningen core.async

我想知道如何获取Clojure中的通道大小。我用count尝试过,但不支持。Clojure文档通常很好,但是这次我找不到任何东西。

例:

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

PIN*_*INK 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
Run Code Online (Sandbox Code Playgroud)

在这里进一步阅读