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

ghedeon

01/17/2019, 11:34 AM
any
ReceiveChannel.asLiveData()
implementations?
s

streetsofboston

01/17/2019, 12:45 PM
I'm implementing something like this for our company's MVVM framework.
g

ghedeon

01/17/2019, 12:58 PM
do you mind sharing a snippet?
a

Allan Wang

01/18/2019, 2:10 AM
If you want to keep the channel alive, you can create a producer that will only pass events when a lifecycleObserver is not destroyed. The other method, which I'm looking into for my projects, is to create a
BroadcastChannel
, and add a method that will open a subscription and listen when a lifecycle starts, and close the receiver when the subscription ends. The use of a broadcast channel is to both ensure that the send channel doesn't close and to allow multiple listeners. This is similar to how a publish subject would operate in rxjava
3 Views