Skip to content

Commit

Permalink
Upgrade to ZIO 2.0.0-M6 (#280)
Browse files Browse the repository at this point in the history
* upgrade to zio 2.0.0-m6

* fix scala 3 issue

* reduce repetitions on scala.js

* revert test changes
  • Loading branch information
adamgfraser authored Nov 21, 2021
1 parent d5a140d commit fe9db38
Show file tree
Hide file tree
Showing 11 changed files with 287 additions and 156 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
fail-fast: false
matrix:
java: ['adopt@1.8', 'adopt@1.11']
scala: ['2.11.12', '2.12.14', '2.13.6', '3.0.2']
scala: ['2.11.12', '2.12.14', '2.13.6', '3.1.0']
steps:
- name: Checkout current branch
uses: actions/checkout@v2.3.4
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ inThisBuild(
addCommandAlias("fmt", "all scalafmtSbt scalafmt test:scalafmt")
addCommandAlias("check", "all scalafmtSbtCheck scalafmtCheck test:scalafmtCheck")

val zioVersion = "2.0.0-M4"
val zioVersion = "2.0.0-M6-2"

lazy val root = project
.in(file("."))
Expand Down
2 changes: 1 addition & 1 deletion project/BuildHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object BuildHelper {
val Scala211: String = versions("2.11")
val Scala212: String = versions("2.12")
val Scala213: String = versions("2.13")
val ScalaDotty: String = versions("3.0")
val ScalaDotty: String = versions("3.1")

def buildInfoSettings(packageName: String) =
Seq(
Expand Down
7 changes: 5 additions & 2 deletions zio-query/shared/src/main/scala/zio/query/Cache.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package zio.query

import zio.{ IO, Ref, UIO, ZTraceElement }
import zio.{ IO, Ref, UIO, ZIO, ZTraceElement }
import zio.stacktracer.TracingImplicits.disableAutoTrace

/**
Expand Down Expand Up @@ -49,7 +49,7 @@ object Cache {
* Constructs an empty cache.
*/
def empty(implicit trace: ZTraceElement): UIO[Cache] =
Ref.make(Map.empty[Any, Any]).map(new Default(_))
ZIO.succeed(Cache.unsafeMake())

private final class Default(private val state: Ref[Map[Any, Any]]) extends Cache {

Expand All @@ -75,4 +75,7 @@ object Cache {
def remove[E, A](request: Request[E, A])(implicit trace: ZTraceElement): UIO[Unit] =
state.update(_ - request)
}

private[query] def unsafeMake(): Cache =
new Default(Ref.unsafeMake(Map.empty[Any, Any]))
}
30 changes: 24 additions & 6 deletions zio-query/shared/src/main/scala/zio/query/DataSource.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package zio.query

import zio.{ Chunk, NeedsEnv, ZIO, ZTraceElement }
import zio.{ Chunk, NeedsEnv, ZEnvironment, ZIO, ZTraceElement }
import zio.stacktracer.TracingImplicits.disableAutoTrace

/**
Expand Down Expand Up @@ -116,17 +116,35 @@ trait DataSource[-R, -A] { self =>
/**
* Provides this data source with its required environment.
*/
final def provide(r: Described[R])(implicit ev: NeedsEnv[R]): DataSource[Any, A] =
provideSome(Described(_ => r.value, s"_ => ${r.description}"))
@deprecated("use provideEnvironment", "2.0.0")
final def provide(r: Described[ZEnvironment[R]])(implicit ev: NeedsEnv[R]): DataSource[Any, A] =
provideEnvironment(r)

/**
* Provides this data source with its required environment.
*/
final def provideEnvironment(r: Described[ZEnvironment[R]])(implicit ev: NeedsEnv[R]): DataSource[Any, A] =
provideSomeEnvironment(Described(_ => r.value, s"_ => ${r.description}"))

/**
* Provides this data source with part of its required environment.
*/
@deprecated("use provideSomeEnvironment", "2.0.0")
final def provideSome[R0](
f: Described[ZEnvironment[R0] => ZEnvironment[R]]
)(implicit ev: NeedsEnv[R]): DataSource[R0, A] =
provideSomeEnvironment(f)

/**
* Provides this data source with part of its required environment.
*/
final def provideSome[R0](f: Described[R0 => R])(implicit ev: NeedsEnv[R]): DataSource[R0, A] =
final def provideSomeEnvironment[R0](
f: Described[ZEnvironment[R0] => ZEnvironment[R]]
)(implicit ev: NeedsEnv[R]): DataSource[R0, A] =
new DataSource[R0, A] {
val identifier = s"${self.identifier}.provideSome(${f.description})"
val identifier = s"${self.identifier}.provideSomeEnvironment(${f.description})"
def runAll(requests: Chunk[Chunk[A]])(implicit trace: ZTraceElement): ZIO[R0, Nothing, CompletedRequestMap] =
self.runAll(requests).provideSome(f.value)
self.runAll(requests).provideSomeEnvironment(f.value)
}

/**
Expand Down
Loading

0 comments on commit fe9db38

Please sign in to comment.