servicetalk-concurrent-api/src/main/java/io/servicetalk/concurrent/api/RepeatStrategies.java
/**
     * Creates a new repeat function that adds a delay between repeats. For first repeat, the delay is
     * {@code initialDelay} which is increased exponentially for subsequent repeats.
     *
     * @param maxRepeats Maximum number of allowed repeats, after which the returned {@link IntFunction} will return
     *                   a failed {@link Completable} with {@link TerminateRepeatException} as the cause.
     * @param initialDelay Delay {@link Duration} for the first repeat and increased exponentially with each repeat.
     * @param jitter The jitter to apply to {@code initialDelay} on each repeat.
     * @param maxDelay The maximum amount of delay that will be introduced.
     * @param timerExecutor {@link Executor} to be used to schedule timers for backoff.
     *
     * @return An {@link IntFunction} to be used for repeats which given a repeat count returns a {@link Completable}
     * that terminates successfully when the source has to be repeated or terminates with error if the source should not
     * be repeated.
     */
Creates a new repeat function that adds a delay between repeats. For first repeat, the delay is
initialDelay which is increased exponentially for subsequent repeats.

@param maxRepeats Maximum number of allowed repeats, after which the returned  IntFunction will return
a failed  Completable with  TerminateRepeatException as the cause.
@param initialDelay Delay  Duration for the first repeat and increased exponentially with each repeat.
@param jitter The jitter to apply to  initialDelay on each repeat.
@param maxDelay The maximum amount of delay that will be introduced.
@param timerExecutor  Executor to be used to schedule timers for backoff.

@return An  IntFunction to be used for repeats which given a repeat count returns a  Completable
that terminates successfully when the source has to be repeated or terminates with error if the source should not
be repeated.
Creates a new repeat function that adds a delay between repeats . For first repeat the delay is initialDelay which is increased exponentially for subsequent repeats . @param maxRepeats Maximum number of allowed repeats after which the returned IntFunction will return a failed Completable with TerminateRepeatException as the cause . @param initialDelay Delay Duration for the first repeat and increased exponentially with each repeat . @param jitter The jitter to apply to initialDelay on each repeat . @param maxDelay The maximum amount of delay that will be introduced . @param timerExecutor Executor to be used to schedule timers for backoff . @return An IntFunction to be used for repeats which given a repeat count returns a Completable that terminates successfully when the source has to be repeated or terminates with error if the source should not be repeated .
public static IntFunction<Completable> repeatWithExponentialBackoffDeltaJitter(final int maxRepeats,
                                                                                   final Duration initialDelay,
                                                                                   final Duration jitter,
                                                                                   final Duration maxDelay,
                                                                                   final Executor timerExecutor) {
        checkMaxRetries(maxRepeats);
        requireNonNull(timerExecutor);
        final long initialDelayNanos = initialDelay.toNanos();
        final long jitterNanos = jitter.toNanos();
        final long maxDelayNanos = maxDelay.toNanos();
        final long maxInitialShift = maxShift(initialDelayNanos);
        return repeatCount -> {
            if (repeatCount > maxRepeats) {
                return terminateRepeat();
            }
            final long baseDelayNanos = baseDelayNanos(initialDelayNanos, maxDelayNanos, maxInitialShift, repeatCount);
            return timerExecutor.timer(
                    current().nextLong(max(0, baseDelayNanos - jitterNanos),
                            min(maxDelayNanos, addWithOverflowProtection(baseDelayNanos, jitterNanos))),
                    NANOSECONDS);
        };
    }
public static IntFunction < Completable > repeatWithExponentialBackoffDeltaJitter ( final int maxRepeats , final Duration initialDelay , final Duration jitter , final Duration maxDelay , final Executor timerExecutor ) { checkMaxRetries ( maxRepeats ) ; requireNonNull ( timerExecutor ) ; final long initialDelayNanos = initialDelay . toNanos ( ) ; final long jitterNanos = jitter . toNanos ( ) ; final long maxDelayNanos = maxDelay . toNanos ( ) ; final long maxInitialShift = maxShift ( initialDelayNanos ) ; return repeatCount -> { if ( repeatCount > maxRepeats ) { return terminateRepeat ( ) ; } final long baseDelayNanos = baseDelayNanos ( initialDelayNanos , maxDelayNanos , maxInitialShift , repeatCount ) ; return timerExecutor . timer ( current ( ) . nextLong ( max ( 0 , baseDelayNanos - jitterNanos ) , min ( maxDelayNanos , addWithOverflowProtection ( baseDelayNanos , jitterNanos ) ) ) , NANOSECONDS ) ; } ; }
Creates a new repeat function that adds a delay between repeats.
Creates a new repeat function that adds a delay between repeats .