https://kotlinlang.org logo
#android
Title
# android
l

Lisandro Di Meo

07/15/2022, 3:13 PM
Anyone knows if I should use flows or channels for socket communication ? I'm a little confused with that
g

Giorgos Makris

07/16/2022, 8:50 AM
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

ephemient

07/16/2022, 8:58 AM
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

gildor

07/16/2022, 1:08 PM
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

Giorgos Makris

07/16/2022, 5:33 PM
@Lisandro Di Meo I am so sorry for the misinformation then! @gildor thanks for the correction 🙂
g

gildor

07/17/2022, 2:59 PM
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

Lisandro Di Meo

07/17/2022, 6:44 PM
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)
2 Views