invokeOnFirst

suspend fun <T, O> Iterable<Deferred<T>>.invokeOnFirst(scope: CoroutineScope, cancelOnResult: Boolean = true, callback: suspend (T) -> O): O(source)

Awaits the first Deferred to complete and invokes the callback on its value. Other deferred values are cancelled if cancelOnResult is true.

Return

The result of applying the callback to the first completed value

Parameters

scope

The CoroutineScope in which to await the deferred values

cancelOnResult

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

callback

The suspending function to apply to the first completed value

Type Parameters

T

The type of the deferred values

O

The type of the result after applying the callback


suspend fun <T, O> invokeOnFirst(scope: CoroutineScope, vararg variants: Deferred<T>, cancelOnResult: Boolean = true, callback: suspend (T) -> O): O(source)

Awaits the first Deferred from the given variants to complete and invokes the callback on its value. Other deferred values are cancelled if cancelOnResult is true.

Return

The result of applying the callback to the first completed value

Parameters

scope

The CoroutineScope in which to await the deferred values

variants

The deferred values to race

cancelOnResult

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

callback

The suspending function to apply to the first completed value

Type Parameters

T

The type of the deferred values

O

The type of the result after applying the callback