Skip to content

Commit ad61cff

Browse files
committed
Retry: update docs
1 parent ddf8bd1 commit ad61cff

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

std/shared/src/main/scala/cats/effect/std/Retry.scala

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,49 @@ import scala.reflect.{classTag, ClassTag}
3131
* Glossary:
3232
* - individual delay - the delay between retries
3333
* - cumulative delay - the total delay accumulated across all retries
34+
*
35+
* ==Usage==
36+
*
37+
* ===Retry on all errors===
38+
*
39+
* {{{
40+
* val policy = Retry
41+
* .exponentialBackoff[IO, Throwable](1.second)
42+
* .withMaxRetries(10)
43+
*
44+
* // retries 10 times at most using an exponential backoff strategy
45+
* IO.raiseError(new RuntimeException("oops")).retry(policy)
46+
* }}}
47+
*
48+
* ===Retry on some errors (e.g. TimeoutException)===
49+
*
50+
* {{{
51+
* val policy = Retry
52+
* .exponentialBackoff[IO, Throwable](1.second)
53+
* .withMaxRetries(10)
54+
* .withErrorMatcher(Retry.ErrorMatcher[IO, Throwable].only[TimeoutException])
55+
*
56+
* // retries 10 times at most using an exponential backoff strategy
57+
* IO.raiseError(new TimeoutException("timeout")).retry(policy)
58+
*
59+
* // gives up immediately
60+
* IO.raiseError(new RuntimeException("oops")).retry(policy)
61+
* }}}
62+
*
63+
* ===Retry on all errors except the TimeoutException===
64+
*
65+
* {{{
66+
* val policy = Retry
67+
* .exponentialBackoff[IO, Throwable](1.second)
68+
* .withMaxRetries(10)
69+
* .withErrorMatcher(Retry.ErrorMatcher[IO, Throwable].except[TimeoutException])
70+
*
71+
* // retries 10 times at most using an exponential backoff strategy
72+
* IO.raiseError(new RuntimeException("oops")).retry(policy)
73+
*
74+
* // gives up immediately
75+
* IO.raiseError(new TimeoutException("timeout")).retry(policy)
76+
* }}}
3477
*/
3578
sealed trait Retry[F[_], E] {
3679
import Retry.{Decision, ErrorMatcher, Status}

tests/shared/src/test/scala/cats/effect/std/RetrySpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ class RetrySpec extends BaseSpec {
510510
result <- mtlRetry[F, Errors, Unit](
511511
io,
512512
policy,
513-
(s, e: Errors, d) => EitherT.liftF(ref.update(_ :+ (s, d, e)))
513+
(s, e: Errors, d) => EitherT.liftF(ref.update(_ :+ ((s, d, e))))
514514
).value
515515
attempts <- ref.get
516516
} yield (result, attempts)
@@ -544,7 +544,7 @@ class RetrySpec extends BaseSpec {
544544
result <- mtlRetry[F, Errors, Unit](
545545
io,
546546
policy,
547-
(s, e: Errors, d) => EitherT.liftF(ref.update(_ :+ (s, d, e)))
547+
(s, e: Errors, d) => EitherT.liftF(ref.update(_ :+ ((s, d, e))))
548548
).value
549549
attempts <- ref.get
550550
} yield (result, attempts)

0 commit comments

Comments
 (0)