cats-retry icon indicating copy to clipboard operation
cats-retry copied to clipboard

More examples in docs

Open cb372 opened this issue 5 years ago • 3 comments

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

cb372 avatar Jun 23 '19 17:06 cb372

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 :)

LukaJCB avatar Jun 24 '19 00:06 LukaJCB

An example of followedBy would be good too, e.g. retry 3 times and then switch to exponential backoff

cb372 avatar Jul 01 '19 20:07 cb372

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)

kxa14 avatar May 19 '21 17:05 kxa14