what will be the simplest code for concurrent wait...
# coroutines
c
what will be the simplest code for concurrent waiting on 2 suspend function and finish on first one, cancelling the other one something like awaitFirst(…) or joinFirst()
r
This has been discussed a few times before. Perhaps something like this, or using a supervisorscope to cancel everything? https://kotlinlang.slack.com/archives/C1CFAFJSK/p1627778065023200?thread_ts=1627721102.019900&cid=C1CFAFJSK
🙏 1
b
we copied raceOf from splitties so it will look like:
Copy code
val result = raceOf(
   { suspendFun1() },
   { suspendFun2() },
}
there is a request to add this fun to coroutines lib https://github.com/Kotlin/kotlinx.coroutines/issues/2867
☝️ 1
🙌 2
c
@bezrukov needs the suspending functions to be extensions of a coroutine scope?
Copy code
suspend fun <T> raceOf(vararg racers: suspend CoroutineScope.() -> T): T
b
not necessary, you can make it simply
suspend () -> T
if you want