Skip to content

Commit

Permalink
Fix nested race issue (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostdogpr authored Aug 4, 2020
1 parent 307f2f6 commit c8aec96
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions interop-cats/shared/src/main/scala/zio/interop/cats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,6 @@ private class CatsConcurrent[R] extends CatsMonadError[R, Throwable] with Concur
Left(token.orDie)
}

override final def race[A, B](fa: RIO[R, A], fb: RIO[R, B]): RIO[R, Either[A, B]] = {
def run[C](fc: RIO[R, C]): ZIO[R, Throwable, C] =
fc.interruptible.overrideForkScope(ZScope.global)

run(fa.map(Left(_))) raceFirst run(fb.map(Right(_)))
}

override final def start[A](fa: RIO[R, A]): RIO[R, effect.Fiber[RIO[R, *], A]] =
fa.interruptible.forkDaemon.map(toFiber)

Expand All @@ -247,7 +240,7 @@ private class CatsConcurrent[R] extends CatsMonadError[R, Throwable] with Concur
(run(fa) raceWith run(fb))(
{ case (l, f) => l.fold(f.interrupt *> ZIO.halt(_), ZIO.succeedNow).map(lv => Left((lv, toFiber(f)))) },
{ case (r, f) => r.fold(f.interrupt *> ZIO.halt(_), ZIO.succeedNow).map(rv => Right((toFiber(f), rv))) }
)
).resetForkScope
}

override final def never[A]: RIO[R, A] =
Expand Down

0 comments on commit c8aec96

Please sign in to comment.