ar-g
05/07/2020, 1:03 PMFlow invariant is violated: Emission from another coroutine detected...
It makes sense, the question is how to not violate it and ensure that:
• Request and observing DB happens in parallel
• Exception wrapped and propagated to UI
• UI continues to observe DB
fun getAll(): Flow<Wrap<...>> = flow { //request and observing db happens in parallel
coroutineScope {
launch(<http://Dispatchers.IO|Dispatchers.IO>) {
try {
//start request...
} catch (e){
emit(Wrap(e))//!!! this will throw IllegalStateException: Flow invariant is violated: Emission from another coroutine is detected.
}
}
emitAll(db.flow()) //starts emitting immediately...
}
}
Dominaezzz
05/07/2020, 1:41 PMchannelFlow
.ar-g
05/08/2020, 6:53 AMchannelFlow
is still experimental
.