firstOf

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

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

T

the type of the produced value

deferreds

suspend producers that are started in parallel

Throws

if none of the producers yielded a value

if the coroutine scope is cancelled or any producer throws it