Skip to content

Commit

Permalink
Fix EventClock losing precision
Browse files Browse the repository at this point in the history
  • Loading branch information
shinyhappydan committed Mar 21, 2024
1 parent b15c88e commit 72d306f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ trait CatsIOValues {

implicit final class CatsIOValuesOps[A](private val io: IO[A]) {
def accepted(implicit pos: source.Position): A = {
io.attempt.unsafeRunTimed(45.seconds).getOrElse(fail("IO timed out during .accepted call")) match {
case Left(e) => fail(s"IO failed when it was expected to succeed $e.", e)
case Right(value) => value
}
io.unsafeRunTimed(45.seconds).getOrElse(fail("IO timed out during .accepted call"))
}

def rejected(implicit pos: source.Position): Throwable = rejectedWith[Throwable]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class EventClock(instant: Ref[IO, Instant]) extends Clock[IO] {
override def realTime: IO[FiniteDuration] = toDuration

private def toDuration: IO[FiniteDuration] = instant.get.map { i =>
FiniteDuration(i.toEpochMilli, TimeUnit.MILLISECONDS)
val seconds = FiniteDuration(i.getEpochSecond, TimeUnit.SECONDS)
val nanos = FiniteDuration(i.getNano, TimeUnit.NANOSECONDS)
seconds + nanos
}
}

Expand Down

0 comments on commit 72d306f

Please sign in to comment.