From 5a5777cf0dcd180799f8119f7fdcb60a75b2b774 Mon Sep 17 00:00:00 2001 From: Flavio Brasil Date: Sun, 13 Oct 2024 23:44:16 -0700 Subject: [PATCH] fix schedule.show formatting in JS --- kyo-data/shared/src/main/scala/kyo/Schedule.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kyo-data/shared/src/main/scala/kyo/Schedule.scala b/kyo-data/shared/src/main/scala/kyo/Schedule.scala index ad84a946d..2bd74dbf3 100644 --- a/kyo-data/shared/src/main/scala/kyo/Schedule.scala +++ b/kyo-data/shared/src/main/scala/kyo/Schedule.scala @@ -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))) @@ -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: @@ -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