race

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.

Parameters

context

The CoroutineContext to run the block in.

condition

Optional condition to consider the block as successful.

block

The coroutine block to race.


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.

Parameters

context

The CoroutineContext to run the block in.

block

The coroutine block to race.