repeat Until
suspend fun <R> repeatUntil(maxAttempts: Long = 10, delay: Duration = 500.milliseconds, condition: (R) -> Boolean, block: suspend () -> R): R(source)
Repeats an operation until a condition is met or max attempts are reached.
Return
The result that satisfied the condition
Parameters
max Attempts
The maximum number of attempts (defaults to 10)
delay
The delay between attempts (defaults to 500 milliseconds)
condition
Predicate to test the result; returns true to stop repeating
block
The suspend operation to repeat
Type Parameters
R
The return type of the suspend operation
Throws
if max attempts reached without satisfying condition
Example usage:
val ready = repeatUntil(maxAttempts = 20, delay = 1.seconds, condition = { it.isReady }) {
serviceStatus.check()
}Content copied to clipboard