gpt4 book ai didi

clojure - 查询缓冲 core.async/chan 中的元素数量

转载 作者:行者123 更新时间:2023-12-02 10:26:09 24 4
gpt4 key购买 nike

有一个缓冲的chan,比如说

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

是否可以查询当前chan中有多少个元素?

最佳答案

实例化的 channel 来自 ManyToManyChannel 类型,您可以使用 buf 属性访问 channel 的内部缓冲区。

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

该缓冲区实现了 clojure.lang.Counted,因此它是可数的。

(count (.buf c))
=> 0

关于clojure - 查询缓冲 core.async/chan 中的元素数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30967187/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com