Skip to content

Commit

Permalink
Rename retryingOnAllErrorsMtl -> retryingOnAllMtlErrors. Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
iRevive committed Jan 14, 2020
1 parent 10a8cb3 commit 0e9fdf8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ val root = project
coreJS,
alleycatsJVM,
alleycatsJS,
mtlJVM,
mtlJS,
docs
)
.settings(commonSettings)
Expand Down
10 changes: 5 additions & 5 deletions modules/docs/src/main/mdoc/docs/mtl-combinators.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ MTL retry works independently from `retry.retryingOnSomeErrors`. The operations
`retry.mtl.retryingOnSomeErrors` evaluating retry exclusively on errors produced by `ApplicativeHandle`.
Thus errors produced by `MonadError` are not being taken into account and retry is not triggered.

If you want to retry in case of any error, just chain the methods:
If you want to retry in case of any error, you can chain the methods:
```scala
fa
.retryingOnAllErrors(policy, onError = retry.noop[F, Throwable])
.retryingOnAllErrorsMtl[AppError](policy, onError = retry.noop[F, AppError])
.retryingOnAllMtlErrors[AppError](policy, onError = retry.noop[F, AppError])
```

## `retryingOnSomeErrors`
Expand Down Expand Up @@ -94,7 +94,7 @@ retry.mtl

## `retryingOnAllErrors`

This is useful when you are working with a `ApplicatieHandle[M, E]` and you want to
This is useful when you are working with a `ApplicativeHandle[M, E]` and you want to
retry on all errors.

The API (modulo some type-inference trickery) looks like this:
Expand Down Expand Up @@ -164,13 +164,13 @@ class Service[F[_]: Timer](client: util.FlakyHttpClient)(implicit F: Sync[F], AH

// evaluates retry exclusively on errors produced by ApplicativeHandle.
def findCoolCatGifRetryMtl(policy: RetryPolicy[F]): F[String] =
findCoolCatGif.retryingOnAllErrorsMtl[AppError](policy, logMtlError)
findCoolCatGif.retryingOnAllMtlErrors[AppError](policy, logMtlError)

// evaluates retry on errors produced by MonadError and ApplicativeHandle
def findCoolCatGifRetryAll(policy: RetryPolicy[F]): F[String] =
findCoolCatGif
.retryingOnAllErrors(policy, logError)
.retryingOnAllErrorsMtl[AppError](policy, logMtlError)
.retryingOnAllMtlErrors[AppError](policy, logMtlError)

private def findCoolCatGif: F[String] =
for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class RetryingMtlErrorOps[M[_], A](action: => M[A])(
implicit M: Monad[M]
) {

def retryingOnAllErrorsMtl[E](
def retryingOnAllMtlErrors[E](
policy: RetryPolicy[M],
onError: (E, RetryDetails) => M[Unit]
)(implicit S: Sleep[M], AH: ApplicativeHandle[M, E]): M[A] =
Expand All @@ -24,7 +24,7 @@ final class RetryingMtlErrorOps[M[_], A](action: => M[A])(
onError = onError
)(action)

def retryingOnSomeErrorsMtl[E](
def retryingOnSomeMtlErrors[E](
isWorthRetrying: E => Boolean,
policy: RetryPolicy[M],
onError: (E, RetryDetails) => M[Unit]
Expand Down
14 changes: 7 additions & 7 deletions modules/mtl/shared/src/test/scala/retry/mtl/SyntaxSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SyntaxSpec extends AnyFlatSpec {
type ErrorOr[A] = Either[Throwable, A]
type F[A] = EitherT[ErrorOr, String, A]

behavior of "retryingOnSomeErrorsMtl"
behavior of "retryingOnSomeMtlErrors"

it should "retry until the action succeeds" in new TestContext {
implicit val sleepForEither: Sleep[F] =
Expand All @@ -39,7 +39,7 @@ class SyntaxSpec extends AnyFlatSpec {

val finalResult: F[String] = action
.retryingOnSomeErrors(_ == error, policy, onError)
.retryingOnSomeErrorsMtl[String](_ == "one more time", policy, onMtlError)
.retryingOnSomeMtlErrors[String](_ == "one more time", policy, onMtlError)

assert(finalResult.value == Right(Right("yay")))
assert(attempts == 3)
Expand Down Expand Up @@ -68,7 +68,7 @@ class SyntaxSpec extends AnyFlatSpec {

val finalResult: F[String] = action
.retryingOnSomeErrors(_ == error, policy, onError)
.retryingOnSomeErrorsMtl[String](_ == "one more time", policy, onMtlError)
.retryingOnSomeMtlErrors[String](_ == "one more time", policy, onMtlError)

assert(finalResult.value == Right(Left("nope")))
assert(attempts == 3)
Expand Down Expand Up @@ -97,7 +97,7 @@ class SyntaxSpec extends AnyFlatSpec {

val finalResult: F[String] = action
.retryingOnSomeErrors(_ == error, policy, onError)
.retryingOnSomeErrorsMtl[String](_ == "one more time", policy, onMtlError)
.retryingOnSomeMtlErrors[String](_ == "one more time", policy, onMtlError)

assert(finalResult.value == Right(Left("one more time")))
assert(attempts == 4)
Expand All @@ -112,7 +112,7 @@ class SyntaxSpec extends AnyFlatSpec {
assert(gaveUp)
}

behavior of "retryingOnAllErrorsMtl"
behavior of "retryingOnAllMtlErrors"

it should "retry until the action succeeds" in new TestContext {
implicit val sleepForEither: Sleep[F] =
Expand All @@ -135,7 +135,7 @@ class SyntaxSpec extends AnyFlatSpec {

val finalResult: F[String] = action
.retryingOnAllErrors(policy, onError)
.retryingOnAllErrorsMtl[String](policy, onMtlError)
.retryingOnAllMtlErrors[String](policy, onMtlError)

assert(finalResult.value == Right(Right("yay")))
assert(attempts == 3)
Expand Down Expand Up @@ -164,7 +164,7 @@ class SyntaxSpec extends AnyFlatSpec {

val finalResult: F[String] = action
.retryingOnAllErrors(policy, onError)
.retryingOnAllErrorsMtl[String](policy, onMtlError)
.retryingOnAllMtlErrors[String](policy, onMtlError)

assert(finalResult.value == Right(Left("one more time")))
assert(attempts == 4)
Expand Down

0 comments on commit 0e9fdf8

Please sign in to comment.