I'm attempting to expose data ("packet") received ...
# coroutines
j
I'm attempting to expose data ("packet") received over BLE to the rest of my app. I would like to expose this data via flows but I'm unsure of which API I should use. I don't have a need for previous "packets" so I've ruled out
StateFlow
. I'm currently deciding between
ChannelFlow
and
SharedFlow
. I've looked up the difference between the two types and it appears that the largest differentiator is that
SharedFlow
allows for "Broadcast" like functionality. Is my conclusion correct or is there more fine details between the two types that should influence my choice of one over the other?
j
That is correct, I think using a SharedFlow will be the best approach based on your use case, you might want to consider taking a look into this: https://medium.com/@shivayogih25/android-kotlin-stateflow-vs-flow-vs-sharedflow-vs-livedata-when-to-use-what-3521ebffcb5d
h
If you care that the receiver gets the packets and it's only one receiver, use channel Otherwise use a shared flow
j
@Jorge Cordero Camarena Thanks for the information and the link. This was exactly what I'm looking for