Skip to content

Commit e238921

Browse files
committed
Fix List<Deferred<T>>.race(): T implementation
1 parent 980c49d commit e238921

File tree

1 file changed

+6
-1
lines changed
  • sample/src/androidMain/kotlin/com/louiscad/splittiessample/extensions/coroutines

1 file changed

+6
-1
lines changed

sample/src/androidMain/kotlin/com/louiscad/splittiessample/extensions/coroutines/Racing.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ suspend inline fun <T> raceOf(vararg racers: suspend CoroutineScope.() -> T): T
1919

2020
@PublishedApi
2121
internal suspend fun <T> List<Deferred<T>>.race(): T = select {
22-
forEach { it.onAwait { result -> forEach(Deferred<T>::cancel); result } }
22+
this@race.forEach {
23+
it.onAwait { result ->
24+
this@race.forEach { deferred -> deferred.cancel() }
25+
return@onAwait result
26+
}
27+
}
2328
}

0 commit comments

Comments
 (0)