RI
Size: a a a
RI
RI
suspend fun <T> List<suspend CoroutineScope.() -> T>.race(): T {
val job = Job()
return select {
forEach { task ->
GlobalScope
.async(job) { task() }
.onAwait {
job.cancel()
it
}
}
}
}
RI
RI
suspend fun main() {
val s = listOf<suspend CoroutineScope.() -> String>(
{ delay(3000); println("first"); "first"; throw RuntimeException("Test") },
{ delay(1000); println("second"); "second" },
{ delay(2000); println("third"); "third" }
).race()
delay(4000)
println(s)
}
LS
AM
LS
VP
LS
suspend fun CoroutineScope.handle(message: Message)
Я правильно понимаю, если стоит suspend, то CoroutineScope ресивер особо то и не нужен?LS
IO
IO
АО
coroutineScope { launch { … } }
АО
coroutineScope { launch { … } }
BV
suspend fun <T> List<suspend CoroutineScope.() -> T>.race(): T {
val job = Job()
return select {
forEach { task ->
GlobalScope
.async(job) { task() }
.onAwait {
job.cancel()
it
}
}
}
}
LS
coroutineScope { launch { … } }
I
АО
LS