Skip to content

Commit

Permalink
Update scalafmt to 2.7.5 (#262)
Browse files Browse the repository at this point in the history
* Update scalafmt-core to 2.7.5

* Update formatting

* fix align

* fmt sbt

* refmt

Co-authored-by: Scala Steward <me@scala-steward.org>
  • Loading branch information
etspaceman and scala-steward authored Dec 16, 2020
1 parent c662f14 commit d3f534d
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 86 deletions.
4 changes: 2 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version = 2.3.2
align = more
version = 2.7.5
align.preset = more
maxColumn = 80
12 changes: 6 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ val core = crossProject(JVMPlatform, JSPlatform)
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % catsVersion,
"org.typelevel" %%% "cats-effect" % catsEffectVersion,
"org.scalatest" %%% "scalatest" % scalatestVersion % Test,
"org.scalacheck" %%% "scalacheck" % scalacheckVersion % Test,
"org.typelevel" %%% "cats-laws" % catsVersion % Test,
"org.scalatest" %%% "scalatest" % scalatestVersion % Test,
"org.scalatest" %%% "scalatest" % scalatestVersion % Test,
"org.scalacheck" %%% "scalacheck" % scalacheckVersion % Test,
"org.typelevel" %%% "cats-laws" % catsVersion % Test,
"org.scalatest" %%% "scalatest" % scalatestVersion % Test,
"org.scalatestplus" %%% "scalacheck-1-14" % scalaTestPlusVersion % Test,
"org.typelevel" %%% "discipline-scalatest" % disciplineVersion % Test,
"org.scalacheck" %%% "scalacheck" % scalacheckVersion % Test
"org.typelevel" %%% "discipline-scalatest" % disciplineVersion % Test,
"org.scalacheck" %%% "scalacheck" % scalacheckVersion % Test
),
mimaPreviousArtifacts := Set.empty
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ object instances {
implicit val threadSleepFuture: Sleep[Future] =
(delay: FiniteDuration) => {
val promise = Promise[Unit]()
scheduler.schedule(new Runnable {
def run(): Unit = {
promise.success(())
()
}
}, delay.length, delay.unit)
scheduler.schedule(
new Runnable {
def run(): Unit = {
promise.success(())
()
}
},
delay.length,
delay.unit
)
promise.future
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ object syntax {
onFailure: (A, RetryDetails) => Unit
)(
action: => A
)(
implicit
)(implicit
M: Monad[Id],
S: Sleep[Id]
): A =
Expand Down
59 changes: 28 additions & 31 deletions modules/core/shared/src/main/scala/retry/RetryPolicies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,47 +31,48 @@ object RetryPolicies {
FiniteDuration(safeResultNanos.toLong, TimeUnit.NANOSECONDS)
}

/**
* Don't retry at all and always give up. Only really useful for combining with other policies.
/** Don't retry at all and always give up. Only really useful for combining with other policies.
*/
def alwaysGiveUp[M[_]: Applicative]: RetryPolicy[M] =
RetryPolicy.liftWithShow(Function.const(GiveUp), "alwaysGiveUp")

/**
* Delay by a constant amount before each retry. Never give up.
/** Delay by a constant amount before each retry. Never give up.
*/
def constantDelay[M[_]: Applicative](delay: FiniteDuration): RetryPolicy[M] =
RetryPolicy.liftWithShow(
Function.const(DelayAndRetry(delay)),
show"constantDelay($delay)"
)

/**
* Each delay is twice as long as the previous one. Never give up.
/** Each delay is twice as long as the previous one. Never give up.
*/
def exponentialBackoff[M[_]: Applicative](
baseDelay: FiniteDuration
): RetryPolicy[M] =
RetryPolicy.liftWithShow({ status =>
val delay =
safeMultiply(baseDelay, Math.pow(2, status.retriesSoFar).toLong)
DelayAndRetry(delay)
}, show"exponentialBackOff(baseDelay=$baseDelay)")

/**
* Retry without delay, giving up after the given number of retries.
RetryPolicy.liftWithShow(
{ status =>
val delay =
safeMultiply(baseDelay, Math.pow(2, status.retriesSoFar).toLong)
DelayAndRetry(delay)
},
show"exponentialBackOff(baseDelay=$baseDelay)"
)

/** Retry without delay, giving up after the given number of retries.
*/
def limitRetries[M[_]: Applicative](maxRetries: Int): RetryPolicy[M] =
RetryPolicy.liftWithShow({ status =>
if (status.retriesSoFar >= maxRetries) {
GiveUp
} else {
DelayAndRetry(Duration.Zero)
}
}, show"limitRetries(maxRetries=$maxRetries)")
RetryPolicy.liftWithShow(
{ status =>
if (status.retriesSoFar >= maxRetries) {
GiveUp
} else {
DelayAndRetry(Duration.Zero)
}
},
show"limitRetries(maxRetries=$maxRetries)"
)

/**
* Delay(n) = Delay(n - 2) + Delay(n - 1)
/** Delay(n) = Delay(n - 2) + Delay(n - 1)
*
* e.g. if `baseDelay` is 10 milliseconds, the delays before each retry will be
* 10 ms, 10 ms, 20 ms, 30ms, 50ms, 80ms, 130ms, ...
Expand All @@ -88,8 +89,7 @@ object RetryPolicies {
show"fibonacciBackoff(baseDelay=$baseDelay)"
)

/**
* "Full jitter" backoff algorithm.
/** "Full jitter" backoff algorithm.
* See https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
*/
def fullJitter[M[_]: Applicative](baseDelay: FiniteDuration): RetryPolicy[M] =
Expand All @@ -103,17 +103,15 @@ object RetryPolicies {
show"fullJitter(baseDelay=$baseDelay)"
)

/**
* Set an upper bound on any individual delay produced by the given policy.
/** Set an upper bound on any individual delay produced by the given policy.
*/
def capDelay[M[_]: Applicative](
cap: FiniteDuration,
policy: RetryPolicy[M]
): RetryPolicy[M] =
policy.meet(constantDelay(cap))

/**
* Add an upper bound to a policy such that once the given time-delay
/** Add an upper bound to a policy such that once the given time-delay
* amount <b>per try</b> has been reached or exceeded, the policy will stop
* retrying and give up. If you need to stop retrying once <b>cumulative</b>
* delay reaches a time-delay amount, use [[limitRetriesByCumulativeDelay]].
Expand All @@ -135,8 +133,7 @@ object RetryPolicies {
)
}

/**
* Add an upperbound to a policy such that once the cumulative delay
/** Add an upperbound to a policy such that once the cumulative delay
* over all retries has reached or exceeded the given limit, the
* policy will stop retrying and give up.
*/
Expand Down
13 changes: 5 additions & 8 deletions modules/core/shared/src/main/scala/retry/RetryPolicy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ case class RetryPolicy[M[_]](
show"$show.followedBy($rp)"
)

/**
* Combine this schedule with another schedule, giving up when either of the schedules want to give up
/** Combine this schedule with another schedule, giving up when either of the schedules want to give up
* and choosing the maximum of the two delays when both of the schedules want to delay the next retry.
* The dual of the `meet` operation.
*/
Expand All @@ -40,8 +39,7 @@ case class RetryPolicy[M[_]](
show"$show.join($rp)"
)

/**
* Combine this schedule with another schedule, giving up when both of the schedules want to give up
/** Combine this schedule with another schedule, giving up when both of the schedules want to give up
* and choosing the minimum of the two delays when both of the schedules want to delay the next retry.
* The dual of the `join` operation.
*/
Expand Down Expand Up @@ -91,8 +89,7 @@ case class RetryPolicy[M[_]](
object RetryPolicy {
def lift[M[_]](
f: RetryStatus => PolicyDecision
)(
implicit
)(implicit
M: Applicative[M]
): RetryPolicy[M] =
RetryPolicy[M](decideNextRetry = retryStatus => M.pure(f(retryStatus)))
Expand All @@ -112,8 +109,8 @@ object RetryPolicy {
): RetryPolicy[M] =
withShow(rs => Applicative[M].pure(decideNextRetry(rs)), pretty)

implicit def boundedSemilatticeForRetryPolicy[M[_]](
implicit M: Applicative[M]
implicit def boundedSemilatticeForRetryPolicy[M[_]](implicit
M: Applicative[M]
): BoundedSemilattice[RetryPolicy[M]] =
new BoundedSemilattice[RetryPolicy[M]] {
override def empty: RetryPolicy[M] =
Expand Down
21 changes: 7 additions & 14 deletions modules/core/shared/src/main/scala/retry/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ package object retry {
onFailure: (A, RetryDetails) => M[Unit],
status: RetryStatus,
a: A
)(
implicit
)(implicit
M: Monad[M],
S: Sleep[M]
): M[Either[RetryStatus, A]] =
Expand All @@ -44,8 +43,7 @@ package object retry {
onFailure: (A, RetryDetails) => M[Unit]
)(
action: => M[A]
)(
implicit
)(implicit
M: Monad[M],
S: Sleep[M]
): M[A] = M.tailRecM(RetryStatus.NoRetriesYet) { status =>
Expand All @@ -63,8 +61,7 @@ package object retry {
onError: (E, RetryDetails) => M[Unit],
status: RetryStatus,
attempt: Either[E, A]
)(
implicit
)(implicit
ME: MonadError[M, E],
S: Sleep[M]
): M[Either[RetryStatus, A]] = attempt match {
Expand Down Expand Up @@ -93,8 +90,7 @@ package object retry {
onError: (E, RetryDetails) => M[Unit]
)(
action: => M[A]
)(
implicit
)(implicit
ME: MonadError[M, E],
S: Sleep[M]
): M[A] = ME.tailRecM(RetryStatus.NoRetriesYet) { status =>
Expand All @@ -118,8 +114,7 @@ package object retry {
onError: (E, RetryDetails) => M[Unit]
)(
action: => M[A]
)(
implicit
)(implicit
ME: MonadError[M, E],
S: Sleep[M]
): M[A] =
Expand All @@ -138,8 +133,7 @@ package object retry {
onError: (E, RetryDetails) => M[Unit]
)(
action: => M[A]
)(
implicit
)(implicit
ME: MonadError[M, E],
S: Sleep[M]
): M[A] = {
Expand Down Expand Up @@ -172,8 +166,7 @@ package object retry {
onError: (E, RetryDetails) => M[Unit]
)(
action: => M[A]
)(
implicit
)(implicit
ME: MonadError[M, E],
S: Sleep[M]
): M[A] =
Expand Down
10 changes: 4 additions & 6 deletions modules/core/shared/src/main/scala/retry/syntax/retry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ final class RetryingOps[M[_], A](action: => M[A]) {
wasSuccessful: A => Boolean,
policy: RetryPolicy[M],
onFailure: (A, RetryDetails) => M[Unit]
)(
implicit
)(implicit
M: Monad[M],
S: Sleep[M]
): M[A] = retryingOnFailures(wasSuccessful, policy, onFailure)
Expand All @@ -31,8 +30,7 @@ final class RetryingOps[M[_], A](action: => M[A]) {
wasSuccessful: A => Boolean,
policy: RetryPolicy[M],
onFailure: (A, RetryDetails) => M[Unit]
)(
implicit
)(implicit
M: Monad[M],
S: Sleep[M]
): M[A] =
Expand All @@ -43,8 +41,8 @@ final class RetryingOps[M[_], A](action: => M[A]) {
)(action)
}

final class RetryingErrorOps[M[_], A, E](action: => M[A])(
implicit M: MonadError[M, E]
final class RetryingErrorOps[M[_], A, E](action: => M[A])(implicit
M: MonadError[M, E]
) {
def retryingOnAllErrors(
policy: RetryPolicy[M],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ class PackageObjectSpec extends AnyFlatSpec {
assert(finalResult == Left("nope"))
assert(attempts == 3)
assert(errors.toList == List("one more time", "one more time"))
assert(!gaveUp) // false because onError is only called when the error is worth retrying
assert(
!gaveUp
) // false because onError is only called when the error is worth retrying
}

it should "retry until the policy chooses to give up" in new TestContext {
Expand Down Expand Up @@ -261,7 +263,9 @@ class PackageObjectSpec extends AnyFlatSpec {
assert(finalResult == Left("nope"))
assert(attempts == 3)
assert(errors.toList == List("one more time", "one more time"))
assert(!gaveUp) // false because onError is only called when the error is worth retrying
assert(
!gaveUp
) // false because onError is only called when the error is worth retrying
}

it should "retry until the policy chooses to give up due to errors" in new TestContext {
Expand Down
4 changes: 3 additions & 1 deletion modules/core/shared/src/test/scala/retry/SyntaxSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ class SyntaxSpec extends AnyFlatSpec {
assert(finalResult == Left("nope"))
assert(attempts == 3)
assert(errors.toList == List("one more time", "one more time"))
assert(!gaveUp) // false because onError is only called when the error is worth retrying
assert(
!gaveUp
) // false because onError is only called when the error is worth retrying
}

it should "retry until the policy chooses to give up" in new TestContext {
Expand Down
6 changes: 2 additions & 4 deletions modules/mtl/shared/src/main/scala/retry/mtl/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ package object mtl {
onError: (E, RetryDetails) => M[Unit]
)(
action: => M[A]
)(
implicit
)(implicit
M: Monad[M],
AH: Handle[M, E],
S: Sleep[M]
Expand Down Expand Up @@ -57,8 +56,7 @@ package object mtl {
onError: (E, RetryDetails) => M[Unit]
)(
action: => M[A]
)(
implicit
)(implicit
M: Monad[M],
AH: Handle[M, E],
S: Sleep[M]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ trait RetrySyntax {
new RetryingMtlErrorOps[M, A](action)
}

final class RetryingMtlErrorOps[M[_], A](action: => M[A])(
implicit M: Monad[M]
final class RetryingMtlErrorOps[M[_], A](action: => M[A])(implicit
M: Monad[M]
) {

def retryingOnAllMtlErrors[E](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ class PackageObjectSpec extends AnyFlatSpec {
assert(finalResult.value == Right(Left("nope")))
assert(attempts == 3)
assert(errors.toList == List("one more time", "one more time"))
assert(!gaveUp) // false because onError is only called when the error is worth retrying
assert(
!gaveUp
) // false because onError is only called when the error is worth retrying
}

it should "retry until the policy chooses to give up" in new TestContext {
Expand Down
4 changes: 3 additions & 1 deletion modules/mtl/shared/src/test/scala/retry/mtl/SyntaxSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ class SyntaxSpec extends AnyFlatSpec {
assert(finalResult.value == Right(Left("nope")))
assert(attempts == 3)
assert(errors.toList == List(Right("one more time"), Left(error)))
assert(!gaveUp) // false because onError is only called when the error is worth retrying
assert(
!gaveUp
) // false because onError is only called when the error is worth retrying
}

it should "retry until the policy chooses to give up" in new TestContext {
Expand Down

0 comments on commit d3f534d

Please sign in to comment.