Hello, is `Channel` still preferred over `Flow` ...
# coroutines
g
Hello, is
Channel
still preferred over
Flow
for use cases that involve multiple emitters/listeners for a data stream? From what I've read online, Flow is meant to be a safer alternative to Channel, but seems best used for one to one communication?
t
There are 2 kinds of `Flow`s: cold and hot. Cold flows wait for a consumer to subscribe before emitting, and re-emit the same sequence to each subscriber independently of each other. Hot flows could start emitting before having any subscriber, and may not send the same sequence to each subscriber. A good example is a flow backed by a callback (click event, etc).
There is currently a way to broadcast events emitted by a flow to multiple listeners: the
broadcastIn(CoroutineScope)
operator.
z
channels and flows are not mutually exclusive
Channels are a synchronization primitive for communicating between coroutines,
Flow<T>
is for exposing an API for asynchronous emissions of
T
over time
Ô׼ 1
g
Thanks Thibault and Zak! that's very helpful
­čĹŹ 1