RacingScope

interface RacingScope<in Result> : CoroutineScope

A scope that allows racing multiple coroutine blocks against each other. The first block to complete successfully will provide the result, and all other blocks will be cancelled.

Parameters

Result

The type of value that will be returned by the racing blocks.

Properties

Link copied to clipboard

Functions

Link copied to clipboard
suspend fun <A> CoroutineScope.awaitAll(block: suspend AwaitAllScope.() -> A): A
Link copied to clipboard
fun <Error, Result> RacingScope<Result>.race(handleError: RaiseHandler<Error>, context: CoroutineContext = EmptyCoroutineContext, block: suspend RaiseScope<Error>.() -> Result)

Races a coroutine block against other blocks in the racing scope. If the block raises an error, it will be handled by handleError. If the block throws an exception, it will be handled by kotlinx.coroutines.CoroutineExceptionHandler. The block will be cancelled if another block completes first.

fun <Result> RacingScope<Result>.race(context: CoroutineContext = EmptyCoroutineContext, condition: (Result) -> Boolean = { true }, block: suspend CoroutineScope.() -> Result)

Races a coroutine block against other blocks in the racing scope. If the block throws an exception, it will be handled by CoroutineExceptionHandler. The block will be cancelled if another block completes first.

Link copied to clipboard
abstract fun raceOrThrow(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> Result)

Races a coroutine block against other blocks in the racing scope. If the block throws an exception, it will be propagated and cancel the entire racing scope. The block will be cancelled if another block completes first.

Link copied to clipboard
fun <Error, Result> RacingScope<Result>.raceOrThrow(handleError: RaiseHandler<Error>, context: CoroutineContext = EmptyCoroutineContext, block: suspend RaiseScope<Error>.() -> Result)

Races a coroutine block against other blocks in the racing scope. If the block raises an error, it will be handled by handleError. The block will be cancelled if another block completes first.