Skip to content

Commit

Permalink
ZIO 2.0.0 (#546)
Browse files Browse the repository at this point in the history
* ZIO 2.0.0

* fix java version issue

Co-authored-by: Adam Fraser <[email protected]>
  • Loading branch information
vigoo and adamgfraser authored Jun 24, 2022
1 parent ddadbdf commit 78cc6de
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 67 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ lazy val root = project
unusedCompileDependenciesFilter -= moduleFilter("org.scala-js", "scalajs-library")
)

val zioVersion = "2.0.0-RC6"
val zioVersion = "2.0.0"
val catsVersion = "2.6.1"
val catsEffectVersion = "3.2.9"
val catsMtlVersion = "1.2.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.typelevel.discipline.scalatest.FunSuiteDiscipline
import zio.*
import zio.managed.*

import java.time.temporal.ChronoUnit
import java.time.{ Instant, LocalDateTime, OffsetDateTime, ZoneOffset }
import java.util.concurrent.TimeUnit
import scala.concurrent.ExecutionContext
Expand Down Expand Up @@ -42,6 +43,9 @@ private[zio] trait CatsSpecBase
def currentTime(unit: => TimeUnit)(implicit trace: Trace): UIO[Long] =
ZIO.succeed(ticker.ctx.now().toUnit(unit).toLong)

def currentTime(unit: => ChronoUnit)(implicit trace: Trace, d: DummyImplicit): UIO[Long] =
ZIO.succeed(unit.between(Instant.EPOCH, Instant.ofEpochMilli(ticker.ctx.now().toMillis)))

def currentDateTime(implicit trace: Trace): UIO[OffsetDateTime] =
ZIO.succeed(OffsetDateTime.ofInstant(Instant.ofEpochMilli(ticker.ctx.now().toMillis), ZoneOffset.UTC))

Expand All @@ -68,7 +72,10 @@ private[zio] trait CatsSpecBase
def unsafeRun[E, A](io: IO[E, A])(implicit ticker: Ticker): Exit[E, Option[A]] =
try {
var exit: Exit[E, Option[A]] = Exit.succeed(Option.empty[A])
runtime.unsafeRunAsyncWith[E, Option[A]](io.asSome)(exit = _)
Unsafe.unsafeCompat { implicit u =>
val fiber = runtime.unsafe.fork[E, Option[A]](io.asSome)
fiber.unsafe.addObserver(exit = _)
}
ticker.ctx.tickAll(FiniteDuration(1, TimeUnit.SECONDS))
exit
} catch {
Expand All @@ -78,16 +85,17 @@ private[zio] trait CatsSpecBase
}

implicit def runtime(implicit ticker: Ticker): Runtime[Any] = {
val executor = Executor.fromExecutionContext(1024)(ticker.ctx)
val blockingExecutor = Executor.fromExecutionContext(1024)(ticker.ctx)
val fiberId = FiberId.unsafeMake(Trace.empty)
val executor = Executor.fromExecutionContext(ticker.ctx)
val blockingExecutor = Executor.fromExecutionContext(ticker.ctx)
val fiberId = Unsafe.unsafeCompat(implicit u => FiberId.make(Trace.empty))
val fiberRefs = FiberRefs(
Map(
FiberRef.currentExecutor -> ::(fiberId -> executor, Nil),
FiberRef.overrideExecutor -> ::(fiberId -> Some(executor), Nil),
FiberRef.currentBlockingExecutor -> ::(fiberId -> blockingExecutor, Nil)
)
)
Runtime(ZEnvironment.empty, fiberRefs)
val runtimeFlags = RuntimeFlags.default
Runtime(ZEnvironment.empty, fiberRefs, runtimeFlags)
}

implicit val arbitraryAny: Arbitrary[Any] =
Expand Down Expand Up @@ -130,7 +138,7 @@ private[zio] trait CatsSpecBase
eqForZIO[R, Nothing, A]

implicit def execTask(task: Task[Boolean])(implicit ticker: Ticker): Prop =
ZEnv.services.locallyWith(_.add(testClock))(task).toEffect[CIO]
ZLayer.succeed(testClock).apply(task).toEffect[CIO]

implicit def orderForUIOofFiniteDuration(implicit ticker: Ticker): Order[UIO[FiniteDuration]] =
Order.by(unsafeRun(_).toEither.toOption)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ object Enqueue {
def offer(a: A)(implicit trace: Trace): F[Boolean] =
underlying.offer(a).toEffect[F]
def offerAll(as: Iterable[A])(implicit trace: Trace): F[Boolean] =
underlying.offerAll(as).toEffect[F]
underlying.offerAll(as).map(_.isEmpty).toEffect[F]
def shutdown(implicit trace: Trace): F[Unit] =
underlying.shutdown.toEffect[F]
def size(implicit trace: Trace): F[Int] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ object Hub {
def publish(a: A)(implicit trace: Trace): F[Boolean] =
hub.publish(a).toEffect[F]
def publishAll(as: Iterable[A])(implicit trace: Trace): F[Boolean] =
hub.publishAll(as).toEffect[F]
hub.publishAll(as).map(_.isEmpty).toEffect[F]
def shutdown(implicit trace: Trace): F[Unit] =
hub.shutdown.toEffect[F]
def size(implicit trace: Trace): F[Int] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ object Queue {
def offer(a: A)(implicit trace: Trace): F[Boolean] =
underlying.offer(a).toEffect[F]
def offerAll(as: Iterable[A])(implicit trace: Trace): F[Boolean] =
underlying.offerAll(as).toEffect[F]
underlying.offerAll(as).map(_.isEmpty).toEffect[F]
def shutdown(implicit trace: Trace): F[Unit] =
underlying.shutdown.toEffect[F]
def size(implicit trace: Trace): F[Int] =
Expand Down
Loading

0 comments on commit 78cc6de

Please sign in to comment.