linear
fun linear(initialDelay: Duration, multiplier: Double = 1.0, maxDelay: Duration = Duration.INFINITE, randomizationFactor: Double = 0.0): DelayStrategy(source)
A delay strategy that uses a linear backoff algorithm to calculate the next delay duration. The algorithm is based on the formula:
initialDelay + (initialDelay * (attempt - 1) * multiplier) + jitter
, whereattempt
is the current delay attempt which starts at 1.
Example:
linear(500.milliseconds, 1.0, 4.seconds)
// Delay between attempts will be as follows:
// [500ms, 1s, 1.5s, 2s, 2.5s, 3s, 3.5s, 4s, 4s, 4s, ...]
linear(500.milliseconds, 1.0, 4.seconds, 0.1)
// Delay between attempts 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 attempt.
multiplier
The multiplier to increase the delay between attempts.
maxDelay
The maximum delay between attempts. 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%).