linearDelay
fun linearDelay(initialDelay: Duration = 500L.milliseconds, multiplier: Double = 1.0, maxDelay: Duration = 1.minutes, randomizationFactor: Double = 0.0)(source)
Configures the retry delay strategy to use the linear backoff algorithm. The delay between retries is calculated using the formula:
initialDelay + (initialDelay * (attempt - 1) * multiplier) + jitter
, whereattempt
is the current delay attempt which starts at 1.
Example:
linearDelay(500.milliseconds, 1.0, 1.minutes)
// Delay between transitions will be as follows:
// [500ms, 1s, 1.5s, 2s, 2.5s, 3s, 3.5s, 4s, 4s, 4s, ...]
linearDelay(500.milliseconds, 1.0, 1.minutes, 0.1)
// Delay between transitions will be something like:
// [450ms, 1.1s, 1.4s, 2.2s, 2.3s, 3.1s, 3.4s, 4s, 4s, 4s, ...]
Content copied to clipboard
Note:
Because the jitter calculation is based on the newly calculated delay, the new delay could be less than the previous value.
Parameters
initialDelay
the initial delay before the first retry.
multiplier
the multiplier to increase the delay between retries.
maxDelay
the maximum delay between retries. Used as a safety net to prevent infinite delays.
randomizationFactor
the randomization factor to add randomness to the calculated delay (e.g., 0.1 for +/-10%).