repeat With Fixed Delay
suspend fun <R> repeatWithFixedDelay(times: Long = 3, delay: Duration = 500.milliseconds, block: suspend () -> R): R(source)
Repeats a successful operation with constant delay between repetitions.
Return
The result of the last successful execution
Parameters
times
The number of times to repeat after the initial execution (defaults to 3)
delay
The fixed delay between repetitions (defaults to 500 milliseconds)
block
The suspend operation to repeat
Type Parameters
R
The return type of the suspend operation
Throws
if any execution fails
Example usage:
// Health check every 2 seconds
val lastCheck = repeatWithFixedDelay(times = 10, delay = 2.seconds) {
healthService.check()
}Content copied to clipboard