Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Upgrade To ZIO 2.0.0-RC4 (#486)
Browse files Browse the repository at this point in the history
* upgrade zio version

* silence warnings about type being infered as any

* silence warnings about type being infered as any

* scalafix

* fix compilation error
  • Loading branch information
adamgfraser authored Apr 3, 2022
1 parent e8b88d6 commit bd97f19
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 45 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ addCommandAlias(
";zioNio/test;examples/test"
)

val zioVersion = "2.0.0-RC3"
val zioVersion = "2.0.0-RC4"

lazy val zioNio = project
.in(file("nio"))
Expand Down
3 changes: 1 addition & 2 deletions docs/essentials/sockets.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Required imports for snippets:

```scala mdoc:silent
import zio._
import zio.Clock._
import zio.Console._
import zio.nio.channels._
import zio.nio._
Expand All @@ -31,7 +30,7 @@ val server = ZIO.scoped {
} *> ZIO.never
}

def doWork(channel: AsynchronousSocketChannel): ZIO[Console with Clock, Throwable, Unit] = {
def doWork(channel: AsynchronousSocketChannel): ZIO[Any, Throwable, Unit] = {
val process =
for {
chunk <- channel.readChunk(3)
Expand Down
2 changes: 1 addition & 1 deletion examples/src/main/scala/StreamDirWatch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object StreamDirWatch extends ZIOAppDefault {
}
}

override def run: URIO[zio.ZEnv with ZIOAppArgs, ExitCode] =
override def run: URIO[ZIOAppArgs, ExitCode] =
ZIO
.serviceWith[ZIOAppArgs](_.getArgs.toList.headOption)
.flatMap(
Expand Down
6 changes: 3 additions & 3 deletions examples/src/main/scala/StreamsBasedServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package zio.nio.examples
import zio.nio.InetSocketAddress
import zio.nio.channels.AsynchronousServerSocketChannel
import zio.stream._
import zio.{Clock, Console, ExitCode, RIO, Scope, URIO, ZIO, ZIOAppDefault, ZTraceElement, durationInt}
import zio.{Clock, Console, ExitCode, RIO, Scope, UIO, ZIO, ZIOAppDefault, ZTraceElement, durationInt}

object StreamsBasedServer extends ZIOAppDefault {

def run: URIO[Console with Clock with Console, ExitCode] =
def run: UIO[ExitCode] =
ZStream
.scoped(server(8080))
.flatMap(handleConnections(_) { chunk =>
Expand All @@ -26,7 +26,7 @@ object StreamsBasedServer extends ZIOAppDefault {
_ <- server.bindTo(socketAddress)
} yield server

def handleConnections[R <: Console](
def handleConnections[R](
server: AsynchronousServerSocketChannel
)(f: String => RIO[R, Unit])(implicit trace: ZTraceElement): ZStream[R, Throwable, Unit] =
ZStream
Expand Down
4 changes: 2 additions & 2 deletions examples/src/main/scala/TextFileDump.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import zio.stream.ZStream
*/
object TextFileDump extends ZIOAppDefault {

override def run: URIO[zio.ZEnv with ZIOAppArgs, ExitCode] = {
override def run: URIO[ZIOAppArgs, ExitCode] = {
val charsetEff = ZIO.serviceWith[ZIOAppArgs](s =>
(s.getArgs.toList match {
case _ :: s :: _ => Some(s)
Expand All @@ -35,7 +35,7 @@ object TextFileDump extends ZIOAppDefault {

private def dump(charset: Charset, file: Path)(implicit
trace: ZTraceElement
): ZIO[Console with Any, Exception, Unit] =
): ZIO[Any, Exception, Unit] =
ZIO.scoped {
FileChannel.open(file).flatMapNioBlockingOps { fileOps =>
val inStream: ZStream[Any, Exception, Byte] = ZStream.repeatZIOChunkOption {
Expand Down
4 changes: 2 additions & 2 deletions examples/src/main/scala/ToUppercaseAsAService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object ToUppercaseAsAService extends ZIOAppDefault {

private def handleConnection(
socket: SocketChannel
)(implicit trace: ZTraceElement): ZIO[Any with Console with Clock, IOException, Long] = {
)(implicit trace: ZTraceElement): ZIO[Any, IOException, Long] = {

// this does the processing of the characters received over the channel via a pipeline
// the stream of bytes from the channel is piped, then written back to the same channel's sink
Expand All @@ -45,7 +45,7 @@ object ToUppercaseAsAService extends ZIOAppDefault {
}
}

override def run: URIO[zio.ZEnv with ZIOAppArgs, ExitCode] = {
override def run: URIO[ZIOAppArgs, ExitCode] = {
val portEff = ZIO.serviceWith[ZIOAppArgs](
_.getArgs.toList.headOption
.flatMap(s => catching(classOf[IllegalArgumentException]).opt(s.toInt))
Expand Down
10 changes: 5 additions & 5 deletions nio/src/main/scala/zio/nio/channels/AsynchronousChannel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ abstract class AsynchronousByteChannel private[channels] (protected val channel:
*
* More than one write operation may be performed to write out the entire chunk.
*/
final def writeChunk(chunk: Chunk[Byte])(implicit trace: ZTraceElement): ZIO[Clock, IOException, Unit] =
final def writeChunk(chunk: Chunk[Byte])(implicit trace: ZTraceElement): ZIO[Any, IOException, Unit] =
for {
b <- Buffer.byte(chunk)
_ <- write(b).repeatWhileZIO(_ => b.hasRemaining)
} yield ()

def sink()(implicit trace: ZTraceElement): ZSink[Clock, IOException, Byte, Byte, Long] = sink(Buffer.byte(5000))
def sink()(implicit trace: ZTraceElement): ZSink[Any, IOException, Byte, Byte, Long] = sink(Buffer.byte(5000))

/**
* A sink that will write all the bytes it receives to this channel.
Expand All @@ -70,7 +70,7 @@ abstract class AsynchronousByteChannel private[channels] (protected val channel:
*/
def sink(
bufferConstruct0: => UIO[ByteBuffer]
)(implicit trace: ZTraceElement): ZSink[Clock, IOException, Byte, Byte, Long] =
)(implicit trace: ZTraceElement): ZSink[Any, IOException, Byte, Byte, Long] =
ZSink.fromPush {
val bufferConstruct = bufferConstruct0
for {
Expand All @@ -79,7 +79,7 @@ abstract class AsynchronousByteChannel private[channels] (protected val channel:
} yield (_: Option[Chunk[Byte]]).map { chunk =>
def doWrite(total: Int, c: Chunk[Byte])(implicit
trace: ZTraceElement
): ZIO[Any with Clock, IOException, Int] = {
): ZIO[Any, IOException, Int] = {
val x = for {
remaining <- buffer.putChunk(c)
_ <- buffer.flip
Expand All @@ -101,7 +101,7 @@ abstract class AsynchronousByteChannel private[channels] (protected val channel:
)
}
.getOrElse(
countRef.get.flatMap[Clock, (Either[IOException, Long], Chunk[Byte]), Unit](count =>
countRef.get.flatMap[Any, (Either[IOException, Long], Chunk[Byte]), Unit](count =>
ZIO.fail((Right(count), Chunk.empty))
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ final class AsynchronousFileChannel(protected val channel: JAsynchronousFileChan
}
}

def sink(position: Long)(implicit trace: ZTraceElement): ZSink[Clock, IOException, Byte, Byte, Long] =
def sink(position: Long)(implicit trace: ZTraceElement): ZSink[Any, IOException, Byte, Byte, Long] =
sink(position, Buffer.byte(5000))

/**
Expand All @@ -147,13 +147,13 @@ final class AsynchronousFileChannel(protected val channel: JAsynchronousFileChan
def sink(
position: Long,
bufferConstruct: UIO[ByteBuffer]
)(implicit trace: ZTraceElement): ZSink[Clock, IOException, Byte, Byte, Long] =
)(implicit trace: ZTraceElement): ZSink[Any, IOException, Byte, Byte, Long] =
ZSink.fromPush {
for {
buffer <- bufferConstruct
posRef <- Ref.make(position)
} yield (_: Option[Chunk[Byte]]).map { chunk =>
def doWrite(currentPos: Long, c: Chunk[Byte])(implicit trace: ZTraceElement): ZIO[Clock, IOException, Long] = {
def doWrite(currentPos: Long, c: Chunk[Byte])(implicit trace: ZTraceElement): ZIO[Any, IOException, Long] = {
val x = for {
remaining <- buffer.putChunk(c)
_ <- buffer.flip
Expand Down
6 changes: 3 additions & 3 deletions nio/src/main/scala/zio/nio/channels/GatheringByteOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ trait GatheringByteOps {
*/
final def writeChunk(src: Chunk[Byte])(implicit trace: ZTraceElement): IO[IOException, Unit] = writeChunks(List(src))

def sink()(implicit trace: ZTraceElement): ZSink[Clock, IOException, Byte, Byte, Long] = sink(Buffer.byte(5000))
def sink()(implicit trace: ZTraceElement): ZSink[Any, IOException, Byte, Byte, Long] = sink(Buffer.byte(5000))

/**
* A sink that will write all the bytes it receives to this channel. The sink's result is the number of bytes written.
Expand All @@ -70,13 +70,13 @@ trait GatheringByteOps {
*/
def sink(
bufferConstruct: UIO[ByteBuffer]
)(implicit trace: ZTraceElement): ZSink[Clock, IOException, Byte, Byte, Long] =
)(implicit trace: ZTraceElement): ZSink[Any, IOException, Byte, Byte, Long] =
ZSink.fromPush {
for {
buffer <- bufferConstruct
countRef <- Ref.make(0L)
} yield (_: Option[Chunk[Byte]]).map { chunk =>
def doWrite(total: Int, c: Chunk[Byte])(implicit trace: ZTraceElement): ZIO[Clock, IOException, Int] = {
def doWrite(total: Int, c: Chunk[Byte])(implicit trace: ZTraceElement): ZIO[Any, IOException, Int] = {
val x = for {
remaining <- buffer.putChunk(c)
_ <- buffer.flip
Expand Down
2 changes: 1 addition & 1 deletion nio/src/main/scala/zio/nio/file/WatchService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ final class WatchKey private[file] (private val javaKey: JWatchKey) {
* closed, this key will be '''reset'''.
*/
def pollEventsScoped(implicit trace: ZTraceElement): ZIO[Scope, Nothing, List[WatchEvent[_]]] =
pollEvents.withFinalizer(reset)
pollEvents.withFinalizer(_ => reset)

/**
* Resets this watch key, making it eligible to be re-queued in the `WatchService`. A key is typically reset after all
Expand Down
10 changes: 3 additions & 7 deletions nio/src/test/scala/zio/nio/channels/DatagramChannelSpec.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package zio.nio.channels

import zio._
import zio.nio._
import zio.test.Assertion._
import zio.test.{Live, TestClock, TestConsole, TestRandom, TestSystem, _}
import zio.{Clock, Random, _}
import zio.test._

import java.io.IOException

object DatagramChannelSpec extends BaseSpec {

override def spec: Spec[
Annotations with Live with Sized with TestClock with TestConfig with TestConsole with TestRandom with TestSystem with Clock with zio.Console with zio.System with Random,
TestFailure[Any],
TestSuccess
] =
override def spec: ZSpec[TestEnvironment with Scope, Any] =
suite("DatagramChannelSpec")(
test("read/write") {
def echoServer(started: Promise[Nothing, SocketAddress])(implicit trace: ZTraceElement): UIO[Unit] =
Expand Down
2 changes: 1 addition & 1 deletion nio/src/test/scala/zio/nio/channels/FileChannelSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import zio.nio.{BaseSpec, Buffer}
import zio.stream.Stream
import zio.test.Assertion._
import zio.test._
import zio.{Chunk, Clock, Random, UIO, ZIO, ZTraceElement}
import zio.{Chunk, UIO, ZIO, ZTraceElement}

import java.io.EOFException
import java.nio.file.StandardOpenOption
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package zio.nio.channels
import zio.nio.file.Path
import zio.nio.{BaseSpec, Buffer}
import zio.test.Assertion._
import zio.test.{Live, TestClock, TestConsole, TestRandom, TestSystem, _}
import zio.{Chunk, Clock, IO, Random, ZIO}
import zio.test._
import zio.{Chunk, IO, ZIO}

import java.nio.file.{Files, StandardOpenOption}
import scala.io.Source
Expand Down
12 changes: 4 additions & 8 deletions nio/src/test/scala/zio/nio/channels/SelectorSpec.scala
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package zio.nio.channels

import zio._
import zio.nio.channels.SelectionKey.Operation
import zio.nio.{BaseSpec, Buffer, ByteBuffer, SocketAddress}
import zio.test.Assertion._
import zio.test.{Live, TestClock, TestConsole, TestRandom, TestSystem, live, _}
import zio.{Clock, Random, durationInt, _}
import zio.test._

import java.io.IOException
import java.nio.channels.CancelledKeyException

object SelectorSpec extends BaseSpec {

override def spec: Spec[
Annotations with Live with Sized with TestClock with TestConfig with TestConsole with TestRandom with TestSystem with Clock with zio.Console with zio.System with Random,
TestFailure[Any],
TestSuccess
] =
override def spec: ZSpec[TestEnvironment with Scope, Any] =
suite("SelectorSpec")(
test("read/write") {
for {
Expand Down Expand Up @@ -51,7 +47,7 @@ object SelectorSpec extends BaseSpec {

def server(
started: Promise[Nothing, SocketAddress]
)(implicit trace: ZTraceElement): ZIO[Clock with Scope, Exception, Unit] = {
)(implicit trace: ZTraceElement): ZIO[Scope, Exception, Unit] = {
def serverLoop(
scope: Scope,
selector: Selector,
Expand Down
2 changes: 1 addition & 1 deletion nio/src/test/scala/zio/nio/file/FilesSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package zio.nio.file
import zio.nio.BaseSpec
import zio.test.Assertion._
import zio.test._
import zio.{Chunk, Clock, Random, Ref, ZIO}
import zio.{Chunk, Ref, ZIO}

object FilesSpec extends BaseSpec {

Expand Down
4 changes: 1 addition & 3 deletions project/BuildHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ object BuildHelper {
"-language:existentials",
"-explaintypes",
"-Yrangepos",
"-Xlint:_,-missing-interpolator,-type-parameter-shadow",
"-Xlint:_,-missing-interpolator,-type-parameter-shadow,-infer-any",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard"
)
Expand Down Expand Up @@ -131,7 +131,6 @@ object BuildHelper {
"-Ypartial-unification",
"-Yno-adapted-args",
"-Ywarn-inaccessible",
"-Ywarn-infer-any",
"-Ywarn-nullary-override",
"-Ywarn-nullary-unit",
"-Ywarn-unused:params,-implicits",
Expand All @@ -145,7 +144,6 @@ object BuildHelper {
"-Ypartial-unification",
"-Yno-adapted-args",
"-Ywarn-inaccessible",
"-Ywarn-infer-any",
"-Ywarn-nullary-override",
"-Ywarn-nullary-unit",
"-Xexperimental",
Expand Down

0 comments on commit bd97f19

Please sign in to comment.