tuweni / org.apache.tuweni.concurrent.coroutines / kotlinx.coroutines.CoroutineScope / retry

retry

suspend fun <R> CoroutineScope.retry(retryDelay: Long, block: suspend (Int) -> R?): R (source)

Retry a suspending block until a non-null result is obtained.

Parameters

retryDelay - the delay between each attempt

block - the suspending block to be executed

Return
the first non-null result

suspend fun <R> CoroutineScope.retry(retryDelay: Long, maxRetries: Int, block: suspend (Int) -> R?): R? (source)

Retry a suspending block until a non-null result is obtained.

Parameters

retryDelay - the delay between each attempt

maxRetries - the maximum number of attempts

block - the suspending block to be executed

Return
the first non-null result, or null if all attempts fail

suspend fun <R> CoroutineScope.retry(retryDelay: (Int) -> Long?, block: suspend (Int) -> R?): R? (source)

Retry a suspending block until a non-null result is obtained.

Parameters

retryDelay - a function returning the delay that should follow each attempt, or null if no further attempts should be made

block - the suspending block to be executed

Return
the first non-null result, or null if all attempts fail