Is there any way to combine 2 calls like this : ``...
# coroutines
j
Is there any way to combine 2 calls like this :
Copy code
val time = measureTimeMillis {
    val one = async { doSomethingUsefulOne() }
    val two = async { doSomethingUsefulTwo() }
    println("The answer is ${one.await() + two.await()}")
}
println("Completed in $time ms")
because if for instance one.await() crashes what will happen? or if both crashes, is there any way to handle these errors? Or in case I just want to continue with the execution instead of adding the values just printing them, is there any way to print the first one (the one that did not crash) and the others doesn't (if it crashes)?
m
I guess this is fit with use case functionality that #arrow has
j
In case I wouldn't use Arrow is there any way?
s
“Exceptional Exceptions for Coroutines made easy…?” by Anton Spaans https://link.medium.com/gKOAkJoMw4
l
Use
coroutineScope
around the two
async
calls (but nested in the
measureTimeMillis
lambda.
☝️ 2
j
keeping both async blocks?
l
If you need parallelization, yes, otherwise, the first one delays starting the second one, potentially making the whole process slower.