Skip to content

Commit

Permalink
fix schedule.show formatting in JS
Browse files Browse the repository at this point in the history
  • Loading branch information
fwbrasil committed Oct 14, 2024
1 parent b78dc3d commit 5a5777c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions kyo-data/shared/src/main/scala/kyo/Schedule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ object Schedule:

case class Exponential(initial: Duration, factor: Double) extends Schedule:
def next = Maybe((initial, Exponential(initial * factor, factor)))
def show = s"Schedule.exponential(${initial.show}, $factor)"
def show = s"Schedule.exponential(${initial.show}, ${formatDouble(factor)})"

case class Fibonacci(a: Duration, b: Duration) extends Schedule:
def next = Maybe((a, Fibonacci(b, a + b)))
Expand All @@ -274,7 +274,7 @@ object Schedule:
def next =
val nextDelay = initial.min(maxBackoff)
Maybe((nextDelay, exponentialBackoff(nextDelay * factor, factor, maxBackoff)))
def show = s"Schedule.exponentialBackoff(${initial.show}, $factor, ${maxBackoff.show})"
def show = s"Schedule.exponentialBackoff(${initial.show}, ${formatDouble(factor)}, ${maxBackoff.show})"
end ExponentialBackoff

case class Linear(base: Duration) extends Schedule:
Expand Down Expand Up @@ -341,5 +341,8 @@ object Schedule:
def show = s"(${schedule.show}).delay(${duration.show})"
end Delay

private def formatDouble(d: Double): String =
if d == d.toLong then f"$d%.1f" else d.toString

end internal
end Schedule

0 comments on commit 5a5777c

Please sign in to comment.