Skip to content

Commit

Permalink
Fix blocking issue on ZIO 2
Browse files Browse the repository at this point in the history
  • Loading branch information
vigoo committed Sep 10, 2021
1 parent aa5c861 commit 60abec0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion prox-core/src/main/scala/io/github/vigoo/prox/runner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 6 additions & 2 deletions prox-fs2-3/src/main/scala/io/github/vigoo/prox/ProxFS2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 6 additions & 2 deletions prox-fs2/src/main/scala/io/github/vigoo/prox/ProxFS2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 60abec0

Please sign in to comment.