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

André Thiele

11/24/2020, 4:19 PM
Is it ok to handle one-time events with a SharedFlow instead of the LiveData + Event class approach?
a

Adam Powell

11/24/2020, 4:24 PM
the LiveData + Event class approach is a hacky workaround for not having a SharedFlow equivalent instead. Leave it behind and don't look back
☝️ 4
Can you clarify what you man by, "one time?"
a

André Thiele

11/24/2020, 4:25 PM
ok great, just wanted to be sure here
Just the active subscriber receives the event
a

Adam Powell

11/24/2020, 4:26 PM
"the" as in, "only one subscriber receives" or, "only active subscribers, which may be 0 or many, will all receive the event?"
you can use
Channel.receiveAsFlow()
for the former and SharedFlow for the latter
a

André Thiele

11/24/2020, 4:28 PM
ok thx man!
👍 2
5 Views