https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

Dominaezzz

08/06/2019, 10:26 AM
I have a use case for
BroadcastChannel
but I'm not sure how to expose it. Should I literally expose the
BroadcastChannel
for users to call
openSubscription()
or should I wrap this up?
z

Zach Klippenstein (he/him) [MOD]

08/06/2019, 4:11 PM
BroadcastChannel
includes both the read side and the write side. Assuming you don't want your API consumers to be able to send their own values, it's better to keep the channel private. The read half of
BroadcastChannel
naturally maps to a
Flow
, and there's an extension function to convert it:
asFlow()
(there was even talk of making
BroadcastChannel
implement
Flow
directly for a while).
d

Dominaezzz

08/07/2019, 11:12 AM
Thanks!