Created
March 15, 2020 20:51
-
-
Save vchernyshov/d661e153e768915c5a2b3a23a7338b1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class State<T>(private val scope: CoroutineScope, initialValue: T? = null) { | |
private val channel = | |
initialValue?.let { ConflatedBroadcastChannel(it) } ?: ConflatedBroadcastChannel() | |
var value: T | |
get() = channel.value | |
set(value) { | |
scope.launch { channel.send(value) } | |
} | |
val flow: Flow<T> | |
get() = channel.asFlow() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment