Can someone explain the difference between `asShar...
# coroutines
t
Can someone explain the difference between
asSharedFlow()
on a
MutableSharedFlow
vs just exposing the
MutableSharedFlow
as a
SharedFlow
?
w
If you expose
MutableSharedFlow
as
SharedFlow
then someone could still cast it back to
Mutable..
and send values to it.
asSharedFlow
fully hides the underlying mutable shared flow from consumers
👍 3
t
Thanks, so exposing as SharedFlow for something that is 100% internal is not an error, it's just better habit to use the other one to avoid future possible troubles.
w
Yep both will behave the same, just using
asSharedFlow
is imo good practice. Even if you don’t develop a library, it’s still good to make it impossible to make a mistake by fellow devs — I can imagine someone doing
if (someFlow is MutableSharedFlow) someFlow.castAndSend(x)
with good intentions
👍 2