Hey, I have a buffered channel with max capacity l...
# coroutines
a
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
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
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.