https://kotlinlang.org logo
#coroutines
Title
# coroutines
c

coder82

08/15/2019, 6:13 PM
is there a way to count the total elements remaining in an channel without consuming them? can it be even done?
z

Zach Klippenstein (he/him) [MOD]

08/16/2019, 4:47 AM
There's no API for that. And since channel operations are generally lock-free and atomic, any counting operation would not be linearizable and could be wrong by the time it's returned. That said, if you're in a debugger, you can pause the jvm and inspect the internal linked list to count it manually.
👍 1
1