Do Kotlin coroutines provide a way to continue wit...
# coroutines
g
Do Kotlin coroutines provide a way to continue with the job that is completed first and cancel the rest, similar to the Java structured concurrency code below?
Copy code
fun run(city: String): String {
        return try {
            StructuredTaskScope.ShutdownOnSuccess<String>().use { scope ->
                scope.fork { weatherServiceTwo.getWeather(city) }
                scope.fork { weatherServiceOne.getWeather(city) }
                scope.fork { weatherServiceThree.getWeather(city) }
                scope.join().result()
            }
        } catch (e: Exception) {
            println("Exception occurred: ${e.message}")
            throw RuntimeException("Weather Details not found")
        }
    }
I tried it with
Select
Builder, but it fails if one of the service calls throws an exception.
e
I find it easier to use channels than select
that doesn't handle errors either though, and I don't think there's a simple solution there. do you just discard some subset of them (wrap try-catch-return@), or try to collect them and re-throw somewhere else?