Hello, can someone help me with kotlin channels? I...
# coroutines
l
Hello, can someone help me with kotlin channels? I wanted to create a behavior similar to
ConflatedBroadcastChannel
, but discarding the event when it's broadcasted. Is there any channel implementation that is capable of that?
e
Would
ArrayBroadcastChannel
fit your use-case?
l
Sorry but it doesn't. The
offer
function will fail if the buffer is full For my case it should return true discarding the first element in the queue
e
Let me clarify. You want conflation but you don’t want to deliver the most recent event to the newly joined subscribers? I’m curious as to what is your use-case for that?
l
Yes, that's right. I have an Android application with MVVM. The ViewModel communicates with the View through a channel. The
ConflatedBroadcastChannel
is perfect to keep the last View State. But there are some events the ViewModel may send to the View that should happen only once, such as "Show a snackbar message" or "Navigate to other screen".