diff --git a/prox-core/src/main/scala/io/github/vigoo/prox/runner.scala b/prox-core/src/main/scala/io/github/vigoo/prox/runner.scala index 60e10dcb..47ae4ff6 100644 --- a/prox-core/src/main/scala/io/github/vigoo/prox/runner.scala +++ b/prox-core/src/main/scala/io/github/vigoo/prox/runner.scala @@ -114,7 +114,7 @@ trait ProcessRunnerModule { def waitForExit(): ProxIO[ProcessResult[O, E]] = { for { - exitCode <- effect(nativeProcess.waitFor(), FailedToWaitForExit.apply) + exitCode <- blockingEffect(nativeProcess.waitFor(), FailedToWaitForExit.apply) _ <- runningInput.join output <- runningOutput.join error <- runningError.join diff --git a/prox-core/src/main/scala/io/github/vigoo/prox/runtime.scala b/prox-core/src/main/scala/io/github/vigoo/prox/runtime.scala index 6769ee29..eb95bdd4 100644 --- a/prox-core/src/main/scala/io/github/vigoo/prox/runtime.scala +++ b/prox-core/src/main/scala/io/github/vigoo/prox/runtime.scala @@ -23,6 +23,7 @@ trait ProxRuntime { protected def unit: ProxIO[Unit] protected def pure[A](value: A): ProxIO[A] protected def effect[A](f: => A, wrapError: Throwable => ProxError): ProxIO[A] + protected def blockingEffect[A](f: => A, wrapError: Throwable => ProxError): ProxIO[A] protected def raiseError(error: ProxError): ProxIO[Unit] protected def ioMap[A, B](io: ProxIO[A], f: A => B): ProxIO[B] protected def ioFlatMap[A, B](io: ProxIO[A], f: A => ProxIO[B]): ProxIO[B] diff --git a/prox-fs2-3/src/main/scala/io/github/vigoo/prox/ProxFS2.scala b/prox-fs2-3/src/main/scala/io/github/vigoo/prox/ProxFS2.scala index 46ed8da2..da6eabd5 100644 --- a/prox-fs2-3/src/main/scala/io/github/vigoo/prox/ProxFS2.scala +++ b/prox-fs2-3/src/main/scala/io/github/vigoo/prox/ProxFS2.scala @@ -28,11 +28,15 @@ trait ProxFS2[F[_]] extends Prox { protected override final def pure[A](value: A): ProxIO[A] = Applicative[F].pure(value) - protected override final def effect[A](f: => A, wrapError: Throwable => ProxError): ProxIO[A] = { + protected override final def effect[A](f: => A, wrapError: Throwable => ProxError): ProxIO[A] = Sync[F].adaptError(Sync[F].delay(f)) { case failure: Throwable => wrapError(failure).toThrowable } - } + + protected override final def blockingEffect[A](f: => A, wrapError: Throwable => ProxError): ProxIO[A] = + Sync[F].adaptError(Sync[F].blocking(f)) { + case failure: Throwable => wrapError(failure).toThrowable + } protected override final def raiseError(error: ProxError): ProxIO[Unit] = ApplicativeError[F, Throwable].raiseError(error.toThrowable) diff --git a/prox-fs2/src/main/scala/io/github/vigoo/prox/ProxFS2.scala b/prox-fs2/src/main/scala/io/github/vigoo/prox/ProxFS2.scala index 6e966364..99a2c65f 100644 --- a/prox-fs2/src/main/scala/io/github/vigoo/prox/ProxFS2.scala +++ b/prox-fs2/src/main/scala/io/github/vigoo/prox/ProxFS2.scala @@ -30,11 +30,15 @@ trait ProxFS2[F[_]] extends Prox { protected override final def pure[A](value: A): ProxIO[A] = Applicative[F].pure(value) - protected override final def effect[A](f: => A, wrapError: Throwable => ProxError): ProxIO[A] = { + protected override final def effect[A](f: => A, wrapError: Throwable => ProxError): ProxIO[A] = Sync[F].adaptError(Sync[F].delay(f)) { case failure: Throwable => wrapError(failure).toThrowable } - } + + protected override final def blockingEffect[A](f: => A, wrapError: Throwable => ProxError): ProxIO[A] = + Sync[F].adaptError(blocker.delay(f)) { + case failure: Throwable => wrapError(failure).toThrowable + } protected override final def raiseError(error: ProxError): ProxIO[Unit] = ApplicativeError[F, Throwable].raiseError(error.toThrowable) diff --git a/prox-zstream-2/src/main/scala/io/github/vigoo/prox/ProxZStream.scala b/prox-zstream-2/src/main/scala/io/github/vigoo/prox/ProxZStream.scala index 7fe971d0..71aea99a 100644 --- a/prox-zstream-2/src/main/scala/io/github/vigoo/prox/ProxZStream.scala +++ b/prox-zstream-2/src/main/scala/io/github/vigoo/prox/ProxZStream.scala @@ -42,6 +42,9 @@ trait ProxZStream extends Prox { protected override final def effect[A](f: => A, wrapError: Throwable => ProxError): ProxIO[A] = ZIO.attempt(f).mapError(wrapError) + protected override final def blockingEffect[A](f: => A, wrapError: Throwable => ProxError): ProxIO[A] = + ZIO.attemptBlocking(f).mapError(wrapError) + protected override final def raiseError(error: ProxError): ProxIO[Unit] = ZIO.fail(error) diff --git a/prox-zstream/src/main/scala/io/github/vigoo/prox/ProxZStream.scala b/prox-zstream/src/main/scala/io/github/vigoo/prox/ProxZStream.scala index c63fe2cd..f26cd485 100644 --- a/prox-zstream/src/main/scala/io/github/vigoo/prox/ProxZStream.scala +++ b/prox-zstream/src/main/scala/io/github/vigoo/prox/ProxZStream.scala @@ -2,8 +2,7 @@ package io.github.vigoo.prox import java.io import java.io.IOException - -import zio.blocking.Blocking +import zio.blocking.{Blocking, effectBlocking} import zio.prelude.Identity import zio.stream.{ZSink, ZStream, ZTransducer} import zio._ @@ -43,6 +42,9 @@ trait ProxZStream extends Prox { protected override final def effect[A](f: => A, wrapError: Throwable => ProxError): ProxIO[A] = ZIO.effect(f).mapError(wrapError) + protected override final def blockingEffect[A](f: => A, wrapError: Throwable => ProxError): ProxIO[A] = + effectBlocking(f).mapError(wrapError) + protected override final def raiseError(error: ProxError): ProxIO[Unit] = ZIO.fail(error)