mayojava
10/03/2018, 6:59 AMfun main(args: Array<String>) = runBlocking<Unit> {
try {
failedConcurrentSum()
} catch(e: ArithmeticException) {
println("Computation failed with ArithmeticException")
}
}
suspend fun failedConcurrentSum(): Int = coroutineScope {
val one = async<Int> {
try {
delay(Long.MAX_VALUE) // Emulates very long computation
42
} finally {
println("First child was cancelled")
}
}
val two = async<Int> {
println("Second child throws an exception")
throw ArithmeticException()
}
one.await() + two.await()
}
it doesnt seem to work for me. The parent coroutine still blocks waiting for the first async
after the second threw the exceptionVsevolod Tolstopyatov [JB]
10/03/2018, 1:18 PMDico
10/03/2018, 2:57 PMtwo
coroutine doesn't throw its exception until you call two.await()
which doesn't occur until one.await()
returns.two
is supposed to cancel the parent before await()
is called then I guess I don't know.Vsevolod Tolstopyatov [JB]
10/03/2018, 10:03 PM