From b5ba22e9630e85e6abdf8f3f8afbb9fe441c3d30 Mon Sep 17 00:00:00 2001 From: Jules Ivanic Date: Tue, 14 Jan 2025 06:02:44 +1100 Subject: [PATCH] Optimisation: Prefer `ZIO.fromCompletableFuture` over `ZIO.fromFutureJava` as it doesn't need to use `blocking` (#151) Prefer `ZIO.fromCompletableFuture` over `ZIO.fromFutureJava` as it doesn't need to use `blocking` --- .../zio/temporal/internal/TemporalInteraction.scala | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/core/src/main/scala/zio/temporal/internal/TemporalInteraction.scala b/core/src/main/scala/zio/temporal/internal/TemporalInteraction.scala index 9df2ed74..7641653f 100644 --- a/core/src/main/scala/zio/temporal/internal/TemporalInteraction.scala +++ b/core/src/main/scala/zio/temporal/internal/TemporalInteraction.scala @@ -10,23 +10,20 @@ import scala.concurrent.TimeoutException @internalApi object TemporalInteraction { - def from[A](thunk: => A): TemporalIO[A] = { + def from[A](thunk: => A): TemporalIO[A] = ZIO .attemptBlocking(thunk) .refineToOrDie[TemporalException] - } def fromFuture[A](future: => CompletableFuture[A]): TemporalIO[A] = ZIO - .fromFutureJava(future) + .fromCompletableFuture(future) .refineToOrDie[TemporalException] def fromFutureTimeout[A](future: => CompletableFuture[A]): TemporalIO[Option[A]] = ZIO - .fromFutureJava(future) + .fromCompletableFuture(future) .map(Option(_)) - .catchSome { case _: TimeoutException => - ZIO.none - } + .catchSome { case _: TimeoutException => ZIO.none } .refineToOrDie[TemporalException] }