A while ago, I made a function to race coroutines ...
# coroutines
l
A while ago, I made a function to race coroutines (winner cancels all the losers) thanks to your help, and now that I'm planning to add it to a library since it's not in kotlinx.coroutines, I'd like to have your thoughts on its name, and ideas if any. Here's that function, currently named `raceOf`:
Copy code
suspend fun <T> raceOf(vararg racers: suspend CoroutineScope.() -> T): T = coroutineScope {
    select<T> {
        @UseExperimental(ExperimentalCoroutinesApi::class)
        val racersAsyncList = racers.map { async(start = CoroutineStart.UNDISPATCHED, block = it) }
        racersAsyncList.forEach { racer ->
            racer.onAwait { resultOfWinner ->
                racersAsyncList.forEach { deferred -> deferred.cancel() }
                return@onAwait resultOfWinner
            }
        }
    }
}
s
Since I know javascript I like race. I guess the Java equivalent is
invokeAny
but is quite vague. What is it called in golang?
s
In Arrow it's called
raceN