https://kotlinlang.org logo
Title
g

giso

08/12/2019, 9:05 AM
Hi there, recently I had need for some kind of a MutableLiveData, but easily integratable with Flows and without the Android dependency. I came up with this solution, but I wonder, if there is a simpler solution. Any ideas?
d

Dico

08/12/2019, 9:26 AM
You can use
chan.value
to get the most recent value. Conflated channel sends always succeed, therefore you can use
offer
instead of
send
So
var value
    get() = chan.value
    set(value) { chan.offer(value) }
Just invoke
chan.offer(initialValue)
in an init block
It seems like you could just use a typealias to ConflatedBroadcastChannel.
👍 2
g

giso

08/12/2019, 10:44 AM
You’re right, much easier this way, thanks 🙂
g

gildor

08/12/2019, 1:03 PM
Also, there is work on DataFlow in progress: https://github.com/Kotlin/kotlinx.coroutines/pull/1354
❤️ 1