invokeFirstOf

suspend fun <O> Iterable<DeferredAction<*, O>>.invokeFirstOf(scope: CoroutineScope, cancelOnResult: Boolean = true): O(source)

Invokes the first DeferredAction whose deferred value completes, executing its callback and returning the result. Other deferred actions are cancelled if cancelOnResult is true.

Return

The result of invoking the first completed deferred action

Parameters

scope

The CoroutineScope in which to await the deferred values

cancelOnResult

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

Type Parameters

O

The type of the result after applying callbacks


suspend fun <O> invokeFirstOf(scope: CoroutineScope, vararg variants: DeferredAction<*, O>, cancelOnResult: Boolean = true): O(source)

Invokes the first DeferredAction from the given variants whose deferred value completes, executing its callback and returning the result. Other deferred actions are cancelled if cancelOnResult is true.

Return

The result of invoking the first completed deferred action

Parameters

scope

The CoroutineScope in which to await the deferred values

variants

The deferred actions to race

cancelOnResult

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

Type Parameters

O

The type of the result after applying callbacks