cats-retry
cats-retry copied to clipboard
More examples in docs
There are a couple of "TODO example" on the Combinators page that need to be filled in.
I think a section on the Retry Policies page that maps from a few use cases to Scala code could also be useful, e.g.
- how to retry 5 times, waiting 100 milliseconds between attempts
- how to do exponential backoff but cap the delay between intervals at 1 second
- how to do Fibonacci backoff but give up if the total delay exceeds 5 seconds
Agreed! I was going to do another PR soon with docs for mapDelay
and mapK
, I can pick these up too, if no one else wants to :)
An example of followedBy
would be good too, e.g. retry 3 times and then switch to exponential backoff
Hi @cb372 ,
There is a slight mistake in the documentation. https://cb372.github.io/cats-retry/docs/combinators.html
In the example of retryingOnFailuresAndAllErrors
, the policy
and wasSuccessful
positional arguments are in the wrong order. Just swipe them around would do.
Original:
val io = retryingOnFailuresAndAllErrors(
wasSuccessful = (s: String) => IO.pure(s != "pending"),
policy = RetryPolicies.limitRetries[IO](5),
onFailure = retry.noop[IO, String],
onError = retry.noop[IO, Throwable]
)(flakyRequest)
Corrected:
val io = retryingOnFailuresAndAllErrors(
policy = RetryPolicies.limitRetries[IO](5),
wasSuccessful = (s: String) => IO.pure(s != "pending"),
onFailure = retry.noop[IO, String],
onError = retry.noop[IO, Throwable]
)(flakyRequest)