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

adambl4

02/16/2021, 7:22 AM
Hey, I have a buffered channel with max capacity let’s say 10 and BufferOverflow.SUSPEND, and I want to let sender to send new values to channel only when there are 5 items left in the buffer, not immediately when buffer changed from 10 to 9. Is there a way to check the number of buffered items on the sender side? Thanks.
z

Zach Klippenstein (he/him) [MOD]

02/16/2021, 3:34 PM
There isn't, but why do you need to be so specific? It sounds like you have some specific business logic you are trying to implement with something that might not be the right solution.
e

Erik

02/16/2021, 3:46 PM
Would an alternative approach work for you? Maybe you can use the
MutableSharedFlow<T>.replayCache: List<T>
property to first check the number of items in the replay cache, and then decide to (not) emit into the flow.
3 Views