Skip to content

Commit

Permalink
Optimisation: Prefer ZIO.fromCompletableFuture over `ZIO.fromFuture…
Browse files Browse the repository at this point in the history
…Java` as it doesn't need to use `blocking` (#151)

Prefer `ZIO.fromCompletableFuture` over `ZIO.fromFutureJava` as it doesn't need to use `blocking`
  • Loading branch information
guizmaii authored Jan 13, 2025
1 parent 40429e4 commit b5ba22e
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

0 comments on commit b5ba22e

Please sign in to comment.