failsafe-lib / failsafe

Fault tolerance and resilience patterns for the JVM
https://failsafe.dev
Apache License 2.0
4.17k stars 296 forks source link

Please add `withMaxDelay(Duration)` and `withBackoff(Duration, Duration)` to `RetryPolicy` #293

Closed JayBazuzi closed 2 years ago

JayBazuzi commented 3 years ago

RetryPolicy.withBackoff() currently takes two long and a shared unit, which makes it awkward when the two values are far apart from each other:

new RetryPolicy<>()
    .withDuration(1, 300000 /* 5 minutes, I think */), ChronoUnit.MILLIS));

I wish I could write:

new RetryPolicy<>()
    .withDelay(Duration.ofMillis(1)
    .withMaxDelay(Duration.ofMinutes(5));

or

new RetryPolicy<>()
    .withBackoff(Duration.ofMillis(1), Duration.ofMinutes(5));
jhalterman commented 3 years ago

Good suggestion. withBackoff(Duration, Duration) seems worth supporting and possibly withMaxDuration as well.

jhalterman commented 2 years ago

3.0 has been released, which includes this improvement.