Christopher Elías
12/25/2020, 11:37 PMkenkyee
12/25/2020, 11:43 PMChristopher Elías
12/25/2020, 11:47 PM@Singleton
class PublishSubjectKtx @Inject constructor() {
private val channel = BroadcastChannel<Any>(1)
suspend fun publish(b: Any) {
channel.send(b)
}
fun observe(): Flow<Any> =
channel
.asFlow()
}
The problem with replacing this with StateFlow is that it requires to have an initial value...
private val _stateFlow = MutableStateFlow<Any>(Any)
kenkyee
12/26/2020, 12:28 AMbezrukov
12/26/2020, 7:27 AMkenkyee
12/26/2020, 11:57 AMChristopher Elías
12/29/2020, 3:07 PMbezrukov
12/29/2020, 3:55 PM@Singleton
class PublishSubjectKtx @Inject constructor() {
private val _flow = MutableSharedFlow<Any>(extraBufferCapacity = 1)
suspend fun publish(b: Any) {
_flow.emit(b)
}
fun observe(): Flow<Any> = _flow // you can add .asSharedFlow() for safety, so it will be readonly
}
Christopher Elías
12/29/2020, 4:02 PMursus
12/30/2020, 8:46 AM