Hello, everyone! I want to understand the real use...
# android
b
Hello, everyone! I want to understand the real use case of channels in Kotlin. I have used flows for sequential data collections like API calls. I have gone through the channel documentation here. Has anyone used channels practically in an app? What are their exact use cases, if anyone has experience?
r
Communication between different coroutines. In some suspend function, I get a channel and await the emission from it. At some later point, another place in the application will send some data in the channel. This way I can communicate data between the two coroutines and suspend until some external place does its thing. Also useful for sending events since it allows a bit more customization than shared flows.
s
I use it for sending events as well. Navigation event would be such example. The idea here is that once an event is consumed, no other consumer should be able to receive it.
👍 1
c
i have never used channels except for one time... last week.
specifically. it was because i had something that was a flow. but it was being consumed by multiple collectors but i just wanted it to be collected by only 1 collector. so i moved to a channel and my issue was solved! so my use case was specifically that i just wanted 1 consumer/collector of a hot event stream
👍 2