diff --git a/build.sbt b/build.sbt index c4a79ac9..49465c5b 100644 --- a/build.sbt +++ b/build.sbt @@ -47,11 +47,11 @@ lazy val interopCats = crossProject(JSPlatform, JVMPlatform) .settings(buildInfoSettings) .settings( libraryDependencies ++= Seq( - "dev.zio" %%% "zio" % "1.0.0-RC10-1", + "dev.zio" %%% "zio" % "1.0.0-RC11-1", "org.typelevel" %%% "cats-effect" % "2.0.0-M5" % Optional, "org.typelevel" %%% "cats-mtl-core" % "0.6.0" % Optional, "co.fs2" %%% "fs2-core" % "1.1.0-M1" % Test, - "dev.zio" %%% "zio" % "1.0.0-RC10-1" % Test classifier "tests", + "dev.zio" %%% "core-tests" % "1.0.0-RC11-1" % Test classifier "tests", "org.specs2" %%% "specs2-core" % "4.7.0" % Test, "org.specs2" %%% "specs2-scalacheck" % "4.7.0" % Test, "org.specs2" %%% "specs2-matcher-extra" % "4.7.0" % Test diff --git a/interop-cats/jvm/src/main/scala/zio/interop/Schedule.scala b/interop-cats/jvm/src/main/scala/zio/interop/Schedule.scala index 669cb697..6f3f83fa 100644 --- a/interop-cats/jvm/src/main/scala/zio/interop/Schedule.scala +++ b/interop-cats/jvm/src/main/scala/zio/interop/Schedule.scala @@ -19,7 +19,7 @@ package zio.interop import cats.effect.ConcurrentEffect import zio.ZSchedule.Decision import zio.clock.Clock -import zio.{ TaskR, ZSchedule } +import zio.{ RIO, ZSchedule } import zio.duration.{ Duration => ZDuration } import Schedule.Env import zio.random.Random @@ -388,12 +388,12 @@ object Schedule { import zio.interop.catz._ private[interop] type Env = Random with Clock - private[interop] def toEffect[F[+_], R, A](zio: TaskR[R, A])(implicit R: Runtime[R], F: ConcurrentEffect[F]): F[A] = + private[interop] def toEffect[F[+_], R, A](zio: RIO[R, A])(implicit R: Runtime[R], F: ConcurrentEffect[F]): F[A] = F.liftIO(taskEffectInstances.toIO(zio)) private[interop] def fromEffect[F[+_], R, A]( eff: F[A] - )(implicit R: Runtime[R], F: ConcurrentEffect[F]): TaskR[R, A] = + )(implicit R: Runtime[R], F: ConcurrentEffect[F]): RIO[R, A] = taskEffectInstances.liftIO[A](F.toIO(eff)) final def apply[F[+_]: ConcurrentEffect, S, A, B]( diff --git a/interop-cats/jvm/src/main/scala/zio/interop/catsjvm.scala b/interop-cats/jvm/src/main/scala/zio/interop/catsjvm.scala index 58b75467..92532b67 100644 --- a/interop-cats/jvm/src/main/scala/zio/interop/catsjvm.scala +++ b/interop-cats/jvm/src/main/scala/zio/interop/catsjvm.scala @@ -74,7 +74,7 @@ abstract class CatsInstances extends CatsInstances1 { implicit def taskEffectInstances[R]( implicit runtime: Runtime[R] - ): effect.ConcurrentEffect[TaskR[R, ?]] with SemigroupK[TaskR[R, ?]] = + ): effect.ConcurrentEffect[RIO[R, ?]] with SemigroupK[RIO[R, ?]] = new CatsConcurrentEffect[R](runtime) } @@ -84,7 +84,7 @@ sealed trait CatsInstances1 extends CatsInstances2 { : MonadError[ZIO[R, E, ?], E] with Bifunctor[ZIO[R, ?, ?]] with Alternative[ZIO[R, E, ?]] = new CatsAlternative[R, E] with CatsBifunctor[R] - implicit def taskConcurrentInstances[R]: effect.Concurrent[TaskR[R, ?]] with SemigroupK[TaskR[R, ?]] = + implicit def taskConcurrentInstances[R]: effect.Concurrent[RIO[R, ?]] with SemigroupK[RIO[R, ?]] = new CatsConcurrent[R] implicit def parallelInstance[R, E](implicit M: Monad[ZIO[R, E, ?]]): Parallel[ZIO[R, E, ?], ParIO[R, E, ?]] = @@ -102,11 +102,11 @@ sealed trait CatsInstances2 { private class CatsConcurrentEffect[R](rts: Runtime[R]) extends CatsConcurrent[R] - with effect.ConcurrentEffect[TaskR[R, ?]] - with effect.Effect[TaskR[R, ?]] { + with effect.ConcurrentEffect[RIO[R, ?]] + with effect.Effect[RIO[R, ?]] { override final def runAsync[A]( - fa: TaskR[R, A] + fa: RIO[R, A] )(cb: Either[Throwable, A] => effect.IO[Unit]): effect.SyncIO[Unit] = effect.SyncIO { rts.unsafeRunAsync(fa) { exit => @@ -115,8 +115,8 @@ private class CatsConcurrentEffect[R](rts: Runtime[R]) } override final def runCancelable[A]( - fa: TaskR[R, A] - )(cb: Either[Throwable, A] => effect.IO[Unit]): effect.SyncIO[effect.CancelToken[TaskR[R, ?]]] = + fa: RIO[R, A] + )(cb: Either[Throwable, A] => effect.IO[Unit]): effect.SyncIO[effect.CancelToken[RIO[R, ?]]] = effect.SyncIO { rts.unsafeRun { ZIO.interruptible(fa).fork.flatMap { f => @@ -128,25 +128,25 @@ private class CatsConcurrentEffect[R](rts: Runtime[R]) } } - override final def toIO[A](fa: TaskR[R, A]): effect.IO[A] = + override final def toIO[A](fa: RIO[R, A]): effect.IO[A] = effect.ConcurrentEffect.toIOFromRunCancelable(fa)(this) } -private class CatsConcurrent[R] extends CatsEffect[R] with Concurrent[TaskR[R, ?]] { +private class CatsConcurrent[R] extends CatsEffect[R] with Concurrent[RIO[R, ?]] { - private[this] final def toFiber[A](f: Fiber[Throwable, A]): effect.Fiber[TaskR[R, ?], A] = - new effect.Fiber[TaskR[R, ?], A] { - override final val cancel: TaskR[R, Unit] = f.interrupt.unit + private[this] final def toFiber[A](f: Fiber[Throwable, A]): effect.Fiber[RIO[R, ?], A] = + new effect.Fiber[RIO[R, ?], A] { + override final val cancel: RIO[R, Unit] = f.interrupt.unit - override final val join: TaskR[R, A] = f.join + override final val join: RIO[R, A] = f.join } - override final def liftIO[A](ioa: cats.effect.IO[A]): TaskR[R, A] = + override final def liftIO[A](ioa: cats.effect.IO[A]): RIO[R, A] = Concurrent.liftIO(ioa)(this) - override final def cancelable[A](k: (Either[Throwable, A] => Unit) => effect.CancelToken[TaskR[R, ?]]): TaskR[R, A] = + override final def cancelable[A](k: (Either[Throwable, A] => Unit) => effect.CancelToken[RIO[R, ?]]): RIO[R, A] = ZIO.accessM { r => - ZIO.effectAsyncInterrupt { (kk: TaskR[R, A] => Unit) => + ZIO.effectAsyncInterrupt { (kk: RIO[R, A] => Unit) => val token: effect.CancelToken[Task] = { k(e => kk(eitherToIO(e))).provide(r) } @@ -155,7 +155,7 @@ private class CatsConcurrent[R] extends CatsEffect[R] with Concurrent[TaskR[R, ? } } - override final def race[A, B](fa: TaskR[R, A], fb: TaskR[R, B]): TaskR[R, Either[A, B]] = + override final def race[A, B](fa: RIO[R, A], fb: RIO[R, B]): RIO[R, Either[A, B]] = racePair(fa, fb).flatMap { case Left((a, fiberB)) => fiberB.cancel.const(Left(a)) @@ -163,22 +163,22 @@ private class CatsConcurrent[R] extends CatsEffect[R] with Concurrent[TaskR[R, ? fiberA.cancel.const(Right(b)) } - override final def start[A](fa: TaskR[R, A]): TaskR[R, effect.Fiber[TaskR[R, ?], A]] = + override final def start[A](fa: RIO[R, A]): RIO[R, effect.Fiber[RIO[R, ?], A]] = ZIO.interruptible(fa).fork.map(toFiber) override final def racePair[A, B]( - fa: TaskR[R, A], - fb: TaskR[R, B] - ): TaskR[R, Either[(A, effect.Fiber[TaskR[R, ?], B]), (effect.Fiber[TaskR[R, ?], A], B)]] = + fa: RIO[R, A], + fb: RIO[R, B] + ): RIO[R, Either[(A, effect.Fiber[RIO[R, ?], B]), (effect.Fiber[RIO[R, ?], A], B)]] = (fa raceWith fb)( - { case (l, f) => l.fold(f.interrupt *> TaskR.halt(_), TaskR.succeed).map(lv => Left((lv, toFiber(f)))) }, - { case (r, f) => r.fold(f.interrupt *> TaskR.halt(_), TaskR.succeed).map(rv => Right((toFiber(f), rv))) } + { case (l, f) => l.fold(f.interrupt *> RIO.halt(_), RIO.succeed).map(lv => Left((lv, toFiber(f)))) }, + { case (r, f) => r.fold(f.interrupt *> RIO.halt(_), RIO.succeed).map(rv => Right((toFiber(f), rv))) } ) } private class CatsEffect[R] extends CatsMonadError[R, Throwable] - with effect.Async[TaskR[R, ?]] + with effect.Async[RIO[R, ?]] with CatsSemigroupK[R, Throwable] { @inline final protected[this] def exitToEither[A](e: Exit[Throwable, A]): Either[Throwable, A] = e.fold(_.failures[Throwable] match { @@ -186,9 +186,9 @@ private class CatsEffect[R] case _ => e.toEither }, Right(_)) - @inline final protected[this] def eitherToIO[A]: Either[Throwable, A] => TaskR[R, A] = { - case Left(t) => TaskR.fail(t) - case Right(r) => TaskR.succeed(r) + @inline final protected[this] def eitherToIO[A]: Either[Throwable, A] => RIO[R, A] = { + case Left(t) => RIO.fail(t) + case Right(r) => RIO.succeed(r) } @inline final private[this] def exitToExitCase[A]: Exit[Throwable, A] => ExitCase[Throwable] = { @@ -201,44 +201,44 @@ private class CatsEffect[R] } } - override final def never[A]: TaskR[R, A] = - TaskR.never + override final def never[A]: RIO[R, A] = + RIO.never - override final def async[A](k: (Either[Throwable, A] => Unit) => Unit): TaskR[R, A] = - TaskR.effectAsync { (kk: TaskR[R, A] => Unit) => + override final def async[A](k: (Either[Throwable, A] => Unit) => Unit): RIO[R, A] = + RIO.effectAsync { (kk: RIO[R, A] => Unit) => k(e => kk(eitherToIO(e))) } - override final def asyncF[A](k: (Either[Throwable, A] => Unit) => TaskR[R, Unit]): TaskR[R, A] = + override final def asyncF[A](k: (Either[Throwable, A] => Unit) => RIO[R, Unit]): RIO[R, A] = ZIO.accessM { r => - TaskR.effectAsyncM { (kk: Task[A] => Unit) => + RIO.effectAsyncM { (kk: Task[A] => Unit) => k(e => kk(eitherToIO(e).provide(r))).provide(r).orDie } } - override final def suspend[A](thunk: => TaskR[R, A]): TaskR[R, A] = - ZIO.flatten(TaskR.effect(thunk)) + override final def suspend[A](thunk: => RIO[R, A]): RIO[R, A] = + ZIO.flatten(RIO.effect(thunk)) - override final def delay[A](thunk: => A): TaskR[R, A] = - TaskR.effect(thunk) + override final def delay[A](thunk: => A): RIO[R, A] = + RIO.effect(thunk) - override final def bracket[A, B](acquire: TaskR[R, A])(use: A => TaskR[R, B])( - release: A => TaskR[R, Unit] - ): TaskR[R, B] = + override final def bracket[A, B](acquire: RIO[R, A])(use: A => RIO[R, B])( + release: A => RIO[R, Unit] + ): RIO[R, B] = ZIO.bracket(acquire)(release(_).orDie)(use) override final def bracketCase[A, B]( - acquire: TaskR[R, A] - )(use: A => TaskR[R, B])(release: (A, ExitCase[Throwable]) => TaskR[R, Unit]): TaskR[R, B] = + acquire: RIO[R, A] + )(use: A => RIO[R, B])(release: (A, ExitCase[Throwable]) => RIO[R, Unit]): RIO[R, B] = ZIO.bracketExit(acquire) { (a, exit: Exit[Throwable, _]) => val exitCase = exitToExitCase(exit) release(a, exitCase).orDie }(use) - override def uncancelable[A](fa: TaskR[R, A]): TaskR[R, A] = + override def uncancelable[A](fa: RIO[R, A]): RIO[R, A] = fa.uninterruptible - override final def guarantee[A](fa: TaskR[R, A])(finalizer: TaskR[R, Unit]): TaskR[R, A] = + override final def guarantee[A](fa: RIO[R, A])(finalizer: RIO[R, Unit]): RIO[R, A] = ZIO.accessM { r => fa.provide(r).ensuring(finalizer.provide(r).orDie) } @@ -249,7 +249,7 @@ private class CatsMonad[R, E] extends Monad[ZIO[R, E, ?]] { override final def map[A, B](fa: ZIO[R, E, A])(f: A => B): ZIO[R, E, B] = fa.map(f) override final def flatMap[A, B](fa: ZIO[R, E, A])(f: A => ZIO[R, E, B]): ZIO[R, E, B] = fa.flatMap(f) override final def tailRecM[A, B](a: A)(f: A => ZIO[R, E, Either[A, B]]): ZIO[R, E, B] = - ZIO.suspend(f(a)).flatMap { + ZIO.effectSuspendTotal(f(a)).flatMap { case Left(l) => tailRecM(l)(f) case Right(r) => ZIO.succeed(r) } diff --git a/interop-cats/jvm/src/main/scala/zio/interop/catszmanagedjvm.scala b/interop-cats/jvm/src/main/scala/zio/interop/catszmanagedjvm.scala index 4cdffebf..130eb462 100644 --- a/interop-cats/jvm/src/main/scala/zio/interop/catszmanagedjvm.scala +++ b/interop-cats/jvm/src/main/scala/zio/interop/catszmanagedjvm.scala @@ -47,7 +47,8 @@ final class CatsIOResourceSyntax[F[_], A](private val resource: Resource[F, A]) l.liftIO(res.bracketCase { case (a, r) => CIO.delay( - ZManaged.reserve(Reservation(ZIO.succeed(a), l.liftIO(r(ExitCase.Completed)).orDie.uninterruptible)) + ZManaged + .reserve(Reservation(ZIO.succeed(a), _ => l.liftIO(r(ExitCase.Completed)).orDie.uninterruptible)) ) } { case (_, ExitCase.Completed) => @@ -71,7 +72,7 @@ final class ZManagedSyntax[R, E, A](private val managed: ZManaged[R, E, A]) exte def toResourceZIO(implicit ev: Applicative[ZIO[R, E, ?]]): Resource[ZIO[R, E, ?], A] = Resource - .make(managed.reserve)(_.release.unit) + .make(managed.reserve)(_.release(Exit.unit).unit) .evalMap(_.acquire) def toResource[F[_]](implicit F: Async[F], ev: Effect[ZIO[R, E, ?]]): Resource[F, A] = diff --git a/interop-cats/jvm/src/test/scala/zio/interop/CatsZManagedSyntaxSpec.scala b/interop-cats/jvm/src/test/scala/zio/interop/CatsZManagedSyntaxSpec.scala index a285545c..bb7f824b 100644 --- a/interop-cats/jvm/src/test/scala/zio/interop/CatsZManagedSyntaxSpec.scala +++ b/interop-cats/jvm/src/test/scala/zio/interop/CatsZManagedSyntaxSpec.scala @@ -172,7 +172,7 @@ class CatsZManagedSyntaxSpec extends Specification with AroundTimeout with Defau for { latch <- Promise.make[Nothing, Unit] - managed = ZManaged.reserve(Reservation(latch.await, ZIO.unit)) + managed = ZManaged.reserve(Reservation(latch.await, _ => ZIO.unit)) resource = managed.toResource[CIO] res <- IO { Concurrent