Adds set method to MutableDataSource

This commit is contained in:
ericdecanini 2022-05-23 14:09:18 +02:00
parent 98999c754f
commit b9b0e84704

View file

@ -25,6 +25,9 @@ interface DataSource<T> {
}
interface MutableDataSource<T> : DataSource<T> {
suspend fun set(value: T)
fun post(value: T)
}
@ -42,6 +45,10 @@ open class BehaviorDataSource<T>(private val defaultValue: T? = null) : MutableD
return mutableFlow
}
override suspend fun set(value: T) {
mutableFlow.emit(value)
}
override fun post(value: T) {
mutableFlow.tryEmit(value)
}
@ -58,6 +65,10 @@ open class PublishDataSource<T> : MutableDataSource<T> {
return mutableFlow
}
override suspend fun set(value: T) {
mutableFlow.emit(value)
}
override fun post(value: T) {
mutableFlow.tryEmit(value)
}