Skip to content

Commit e60f16c

Browse files
committed
Retry: update docs
1 parent 20e73e3 commit e60f16c

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

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}

0 commit comments

Comments
 (0)