Skip to content

Commit

Permalink
Retry: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
iRevive committed Jul 28, 2024
1 parent 20e73e3 commit e60f16c
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions std/shared/src/main/scala/cats/effect/std/Retry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,49 @@ import scala.reflect.{classTag, ClassTag}
* Glossary:
* - individual delay - the delay between retries
* - cumulative delay - the total delay accumulated across all retries
*
* ==Usage==
*
* ===Retry on all errors===
*
* {{{
* val policy = Retry
* .exponentialBackoff[IO, Throwable](1.second)
* .withMaxRetries(10)
*
* // retries 10 times at most using an exponential backoff strategy
* IO.raiseError(new RuntimeException("oops")).retry(policy)
* }}}
*
* ===Retry on some errors (e.g. TimeoutException)===
*
* {{{
* val policy = Retry
* .exponentialBackoff[IO, Throwable](1.second)
* .withMaxRetries(10)
* .withErrorMatcher(Retry.ErrorMatcher[IO, Throwable].only[TimeoutException])
*
* // retries 10 times at most using an exponential backoff strategy
* IO.raiseError(new TimeoutException("timeout")).retry(policy)
*
* // gives up immediately
* IO.raiseError(new RuntimeException("oops")).retry(policy)
* }}}
*
* ===Retry on all errors except the TimeoutException===
*
* {{{
* val policy = Retry
* .exponentialBackoff[IO, Throwable](1.second)
* .withMaxRetries(10)
* .withErrorMatcher(Retry.ErrorMatcher[IO, Throwable].except[TimeoutException])
*
* // retries 10 times at most using an exponential backoff strategy
* IO.raiseError(new RuntimeException("oops")).retry(policy)
*
* // gives up immediately
* IO.raiseError(new TimeoutException("timeout")).retry(policy)
* }}}
*/
sealed trait Retry[F[_], E] {
import Retry.{Decision, ErrorMatcher, Status}
Expand Down

0 comments on commit e60f16c

Please sign in to comment.