Bruno Ortiz
11/11/2020, 7:08 PMfun main() = runBlocking<Unit> {
emit()
.onEach {
if (it == 5) error("oof! some random error occurred.")
println(it)
}.catch { println("some error occurred") }
.collect()
}
fun emit() = flow {
for (i in 1..10) {
emit(i)
}
}
This will print "1 2 3 4" and stop. I'd like to print every number except number 5. (I'm doing this to simulate a random error, i know that in this specific case i could filter out the number 5).Adam Powell
11/11/2020, 7:10 PMBruno Ortiz
11/11/2020, 7:13 PMAdam Powell
11/11/2020, 7:26 PM.collect
resumes with an exception all of the associated state from that collection is goneBruno Ortiz
11/11/2020, 7:28 PMwhile(true)
loop. So i think that the retry operator is good enough to restart the loop. Thanks againShalom Halbert
11/12/2020, 11:02 AMSharedFlow
or StateFlow