Hi there, recently I had need for some kind of a M...
# coroutines
g
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
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
Copy code
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
You’re right, much easier this way, thanks 🙂
g
Also, there is work on DataFlow in progress: https://github.com/Kotlin/kotlinx.coroutines/pull/1354
❤️ 1