Kotlin version: 1.6.10
Coroutines version:
Platform: JVM
val list = flow {
emit(1)
}
.flatMapLatest {
flow {
emit("First item for $it")
throw RuntimeException()
}
}
.retryWhen { _, _ ->
emit("Error!")
true
}
.take(6)
.toList()
println(list)
Running this code prints [Error!, Error!, Error!, Error!, Error!, Error!] inside runTest or runBlocking, despite having emit("First item for $it") before the exception throwing.
However, collecting the flow in another dispatcher (for example, Dispatchers.Default, or Dispatchers.IO) will make it work as expected, printing [First item for 1, Error!, First item for 1, Error!, First item for 1, Error!].