firstOf

suspend fun <T> firstOf(vararg deferreds: suspend () -> T): T(source)

Executes the given suspend producers in parallel and returns the first successfully produced value.

This is a non-nullable variant of firstOfOrNull. If no producer yields a value, it throws an IllegalStateException.

Return

the first successfully produced value

Parameters

deferreds

suspend producers that are started in parallel

Type Parameters

T

the type of the produced value

Throws

if none of the producers yielded a value

if the coroutine scope is cancelled or any producer throws it