firstOf

suspend fun <T> CoroutineScope.firstOf(variants: Iterable<Deferred<T>>, cancelOnResult: Boolean = true): T(source)
suspend fun <T> CoroutineScope.firstOf(vararg variants: Deferred<T>, cancelOnResult: Boolean = true): T(source)

Returns the value of the first Deferred from the given variants to complete. Other deferred values are cancelled if cancelOnResult is true.

Return

The value of the first completed deferred

Parameters

variants

The deferred values to race

cancelOnResult

If true, cancels all other deferred values after the first completes. Defaults to true

Type Parameters

T

The type of the deferred values


suspend fun <T> CoroutineScope.firstOf(cancelOnResult: Boolean = true, block: DoWithFirstBuilder<T>.() -> Unit): T(source)

Builds multiple deferred computations using DoWithFirstBuilder and returns the value of the first one to complete. Other deferred computations are cancelled if cancelOnResult is true.

Return

The value of the first completed computation

Parameters

cancelOnResult

If true, cancels all other computations after the first completes. Defaults to true

block

Builder DSL to define the deferred computations

Type Parameters

T

The type of the deferred values