Philip Dukhov
06/01/2023, 12:21 PMinvokeOnCompletion
to each and cancel the rest of them when the first one completes, but maybe there's some built-in way?Sam
06/01/2023, 12:23 PMsuspend fun <T> race(vararg jobs: Deferred<T>): T = try {
select { jobs.forEach { job -> job.onAwait { it } } }
} finally {
jobs.forEach { it.cancelAndJoin() }
}
Sam
06/01/2023, 12:23 PMSam
06/01/2023, 12:26 PMPhilip Dukhov
06/01/2023, 12:29 PM