awaitOrDefault

suspend fun <T> Deferred<T>.awaitOrDefault(timeout: Duration, default: T): T

Awaits this deferred value and returns default if timeout elapses first.

A non-positive timeout returns default without waiting. If the deferred fails, its failure is rethrown unchanged; default signals only a timeout.

Cancellation: on timeout, only the wait is cancelled, never the deferred itself. Cancellation of the calling coroutine, and cancellation of the deferred, are rethrown.

Parameters

timeout

how long to wait for the value.

default

the value returned when the timeout elapses.