Query for cardinality in buffered core.async / chan

Buffered chan

, say

(def c (clojure.core.async/chan 100))

      

Is it possible to query how many elements are inside the chan?

+3


source to share


1 answer


A specific channel is of type ManyToManyChannel

, you can access the internal buffer for a channel using the property buf

.

(.buf c)
 => #<FixedBuffer clojure.core.async.impl.buffers.FixedBuffer@3d67452c>

      



This buffer implements clojure.lang.Counted

, so it is countable.

(count (.buf c))
=> 0

      

+5


source







All Articles