Anyone knows if I should use flows or channels for...
# android
l
Anyone knows if I should use flows or channels for socket communication ? I'm a little confused with that
g
Flows are an abstraction over channels. They do offer more utility tools to help you but they can also have a larger learning curve over channels. It really is up to you!
e
to an extent, it's somewhat akin to the relationship between Iterator and Iterable
for some cases one will be a better match than the other
g
Depends what you mean by "use" You really never want to expose channels in your public API, but you may use channels as implementation details In general, Flow should always be the default choice as soon as it covers your use case and raw channels only for custom stuff or when you need some special semantics such as one to many
Flows are an abstraction over channels
Not all flows, and most implementations from kotlinx.coroutines actually do not use channels under the hood
g
@Lisandro Di Meo I am so sorry for the misinformation then! @gildor thanks for the correction 🙂
g
It's not misinformation, no problem, channels are used as multithread abstraction under the hood, just commented to make it a bit more clear
🙌 2
l
Thanks for answering! I'm currently using websockets from java_websockets to establish communication and to update a livedata. But I'd like to adapt it to use flows (since I guess it's more appropriate instead a simple live data)