I want to run to suspend functions in parallel and return result once the faster one of them returns result. I tried doing the following, but I think it only returns when both of them have finished and it takes too much time, since I'm waiting for both.
val coroutineScope = CoroutineScope(Dispatchers.Main)
val a = coroutineScope.async {
a(context)
}
val b = coroutineScope.async {
b(context)
}
val results = listOf(a, b).awaitAll()
return if (results.any { it is RunSuccess }) {
...
} else {
...
}
Any ideas?