有没有办法在Kotlin频道中找到数量的元素
我正在使用通道,因为我需要一个非阻止队列。我还想通过预摘要(避免在发行之后提取)来维护队列中的一定数量,以便在需要时总是存在元素。
要触发预摘要,我需要知道大小是否降至阈值以下。但是,我在Kotlin通道或接收渠道上没有看到任何.size()方法。有一个实验API .isempty()。
预期尺寸()是反pates的吗?
I am using a Channel because I needed a non-blocking queue. I also want to maintain certain number of elements in the queue by prefetching (to avoid fetch-after-going-empty) so that there are elements always present when needed.
To trigger prefetching, I need to know if the size has fallen below a threshold. However, I do not see any .size() method on Kotlin Channel or ReceiveChannel. There is an experiment api .isEmpty() though.
Is expecting size() here is anti-pattern?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论