Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sbt-scalajs to 1.13.2 #608

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 15 additions & 31 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:
on:
pull_request:
push:
branches: ['master']
branches: ['master', 'series/2.x']
release:
types:
- published
Expand Down Expand Up @@ -47,11 +47,12 @@ jobs:
strategy:
fail-fast: false
matrix:
java: ['adopt@1.8']
scala: ['2.11.12', '2.12.15', '2.13.7', '3.1.1']
java: ['adopt@1.8', '11', '17']
scala: ['2.12.15', '2.13.11', '3.3.0']
platform: ['JVM', 'Native']
steps:
- name: Checkout current branch
uses: actions/checkout@v3.0.0
uses: actions/checkout@v3.3.0
with:
fetch-depth: 0
- name: Setup Scala and Java
Expand All @@ -60,37 +61,20 @@ jobs:
java-version: ${{ matrix.java }}
- name: Cache scala dependencies
uses: coursier/cache-action@v6
- name: Test 2.x
if: ${{ !startsWith(matrix.scala, '3.') }}
run: ./sbt ++${{ matrix.scala }}! test
- name: Test 3.x
if: ${{ startsWith(matrix.scala, '3.') }}
run: ./sbt ++${{ matrix.scala }}! testDotty

testJvms:
runs-on: ubuntu-20.04
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
java: ['11', '17']
steps:
- name: Checkout current branch
uses: actions/checkout@v3.0.0
with:
fetch-depth: 0
- name: Setup Scala and Java
uses: olafurpg/setup-scala@v13
- name: Install libuv
if: matrix.platform == 'Native'
run: sudo apt-get update && sudo apt-get install -y libuv1-dev
- name: Set Swap Space
if: matrix.platform == 'Native'
uses: pierotofy/set-swap-space@master
with:
java-version: ${{ matrix.java }}
- name: Cache scala dependencies
uses: coursier/cache-action@v6
- name: Test
run: ./sbt test
swap-size-gb: 9
- name: Tests
run: ./sbt ++${{ matrix.scala }} zioNio${{ matrix.platform }}/test

ci:
runs-on: ubuntu-20.04
needs: [lint, mdoc, test, testJvms]
needs: [lint, mdoc, test]
steps:
- name: Report successful build
run: echo "ci passed"
Expand Down
36 changes: 32 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
project/zecret
project/travis-deploy-key
project/secrets.tar.xz
target
test-output/
.sbtopts
.bsp
project/.sbt
*.tmp
website/i18n
website/yarn.lock
website/static/api
test-output/
.bloop
.metals
metals.sbt
*/metals.sbt
.idea
coursier
.DS_Store
metals.sbt
project/metals.sbt
project/project/metals.sbt
sbt.json
.bsp/
project/project/
*.iml

# if you are here to add your IDE's files please read this instead:
# https://stackoverflow.com/questions/7335420/global-git-ignore#22885996
website/node_modules
website/.docusaurus
website/build
website/docs
website/static/api*
website/versioned_docs
website/i18n/en.json
website/yarn.lock
website/package-lock.json
website/static/api
.bsp/
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.14.0
16.20.2
21 changes: 1 addition & 20 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
rules = [
Disable
DisableSyntax
ExplicitResultTypes
LeakingImplicitClassVal
NoAutoTupling
NoValInForComprehension
OrganizeImports
ProcedureSyntax
RemoveUnused
]

Disable {
ifSynthetic = [
"scala/Option.option2Iterable"
"scala/Predef.any2stringadd"
]
}

OrganizeImports {
# Allign with IntelliJ IDEA so that they don't fight each other
groupedImports = Merge
}

RemoveUnused {
imports = false // handled by OrganizeImports
}
]
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.watcherExclude": {
"**/target": true
}
}
44 changes: 34 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ inThisBuild(
licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
developers := List(
Developer("jdegoes", "John De Goes", "john@degoes.net", url("http://degoes.net"))
)
),
scalaVersion := "2.13.11",
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision
)
)

Expand All @@ -19,22 +22,41 @@ addCommandAlias(
";zioNio/test;examples/test"
)

val zioVersion = "1.0.12"
val zioVersion = "2.0.16"

lazy val root = crossProject(JVMPlatform, NativePlatform)
.in(file("."))
.settings(publish / skip := true)
.aggregate(zioNio, examples)

lazy val zioNio = project
lazy val zioNio = crossProject(JVMPlatform, NativePlatform)
.in(file("nio"))
.settings(stdSettings("zio-nio"))
.settings(
.settings(crossProjectSettings)
.settings(buildInfoSettings("zio.nio"))
.settings(scala3Settings)
.jvmSettings(
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % zioVersion,
"dev.zio" %% "zio-streams" % zioVersion,
"org.scala-lang.modules" %% "scala-collection-compat" % "2.5.0",
"org.scala-lang.modules" %% "scala-collection-compat" % "2.11.0",
"dev.zio" %% "zio-test" % zioVersion % Test,
"dev.zio" %% "zio-test-sbt" % zioVersion % Test
),
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.settings(dottySettings)
.nativeSettings(Test / fork := false)
.nativeSettings(
libraryDependencies ++= Seq(
"dev.zio" %%% "zio" % zioVersion,
"dev.zio" %%% "zio-streams" % zioVersion,
"org.scala-lang.modules" %%% "scala-collection-compat" % "2.11.0",
"dev.zio" %%% "zio-test" % zioVersion % Test,
"dev.zio" %%% "zio-test-sbt" % zioVersion % Test,
"io.github.cquiroz" %%% "scala-java-time" % "2.5.0"
),
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)

lazy val docs = project
.in(file("zio-nio-docs"))
Expand All @@ -43,21 +65,23 @@ lazy val docs = project
moduleName := "zio-nio-docs",
scalacOptions -= "-Yno-imports",
scalacOptions -= "-Xfatal-warnings",
ScalaUnidoc / unidoc / unidocProjectFilter := inProjects(zioNio),
ScalaUnidoc / unidoc / unidocProjectFilter := inProjects(zioNio.jvm),
ScalaUnidoc / unidoc / target := (LocalRootProject / baseDirectory).value / "website" / "static" / "api",
cleanFiles += (ScalaUnidoc / unidoc / target).value,
docusaurusCreateSite := docusaurusCreateSite.dependsOn(Compile / unidoc).value,
docusaurusPublishGhpages := docusaurusPublishGhpages.dependsOn(Compile / unidoc).value
)
.dependsOn(zioNio)
.dependsOn(zioNio.jvm)
.enablePlugins(MdocPlugin, DocusaurusPlugin, ScalaUnidocPlugin)

lazy val examples = project
lazy val examples = crossProject(JVMPlatform, NativePlatform)
.in(file("examples"))
.settings(stdSettings("examples"))
.settings(
publish / skip := true,
moduleName := "examples"
)
.settings(dottySettings)
.settings(crossProjectSettings)
.settings(buildInfoSettings("examples"))
.settings(scala3Settings)
.dependsOn(zioNio)
26 changes: 13 additions & 13 deletions docs/essentials/blocking.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ Many NIO operations can block the calling thread when called. ZIO-NIO provides A

## Blocking and Non-Blocking Channel Operations

Channel APIs that may block are not exposed on the channel itself. They are accessed via the channel's `useBlocking` method. You provide this method a function that excepts a `BlockingOps` object and returns a `ZIO` effect value. The `BlockingOps` parameter will be appropriate to the type of channel and has the actual blocking I/O effects such as read and write.
Channel APIs that may block are not exposed on the channel itself. They are accessed via the channel's `flatMapBlocking` method. You provide this method a function that excepts a `BlockingOps` object and returns a `ZIO` effect value. The `BlockingOps` parameter will be appropriate to the type of channel and has the actual blocking I/O effects such as read and write.

The `useBlocking` method performs some setup required for safe use of blocking NIO APIs:
The `flatMapBlocking` method performs some setup required for safe use of blocking NIO APIs:

* Puts the channel in blocking mode
* Runs the resulting effect value on ZIO's blocking thread pool, leaving the standard pool unblocked.
* Installs interrupt handling, so the channel will be closed if the ZIO fiber is interrupted. This unblocks the blocked I/O operation. (Note that NIO does not offer a way to interrupt a blocked I/O operation on a channel that does not close the channel).

Non-blocking usage does not require this special handling, but for consistency the non-blocking operations are accessed in a similar way by calling `useNonBlocking` on the channel. For some channels there are some small differences between the blocking and non-blocking APIs. For example, `SocketChannel` only offers the `finishConnect` operation in the non-blocking case, as it is never needed in blocking mode.
Non-blocking usage does not require this special handling, but for consistency the non-blocking operations are accessed in a similar way by calling `flatMapNonBlocking` on the channel. For some channels there are some small differences between the blocking and non-blocking APIs. For example, `SocketChannel` only offers the `finishConnect` operation in the non-blocking case, as it is never needed in blocking mode.

```scala mdoc:silent
import zio.ZIO
Expand All @@ -32,36 +32,36 @@ def readHeader(c: SocketChannel): ZIO[Blocking, IOException, (Chunk[Byte], Chunk
}
```

### Using Managed Channels
### Using Channels

To help with the common use-case where you want to create a channel, there is versions of `useBlocking` and `useNonBlocking` that can be called directly on a managed value providing a channel.
To help with the common use-case where you want to create a channel, there is versions of `flatMapBlocking` and `flatMapNonBlocking` that can be called directly on a ZIO value providing a channel.

`useNioBlocking` provides both the channel and the requested type of operations:
`flatMapNioBlocking` provides both the channel and the requested type of operations:

```scala mdoc:silent
import zio.nio._
import zio.nio.channels._

SocketChannel.open.useNioBlocking { (channel, blockingOps) =>
SocketChannel.open.flatMapNioBlocking { (channel, blockingOps) =>
blockingOps.readChunk(100) <*> channel.remoteAddress
}
```

If you don't need the channel, there's `useNioBlockingOps`:
If you don't need the channel, there's `flatMapNioBlockingOps`:

```scala mdoc:silent
import zio.nio.channels._

SocketChannel.open.useNioBlockingOps { blockingOps =>
SocketChannel.open.flatMapNioBlockingOps { blockingOps =>
blockingOps.readChunk(100)
}
```

To use the channel in non-blocking mode, there's corresponding `useNioNonBlocking` and `useNioNonBlockingOps` methods.
To use the channel in non-blocking mode, there's corresponding `flatMapNioNonBlocking` and `flatMapNioNonBlockingOps` methods.

### Avoiding Asynchronous Boundaries

If you have a complex program that makes more than one call to `useBlocking`, then it may be worth running *all* of the ZIO-NIO parts using the blocking pool. This can be done by wrapping the effect value with your ZIO-NIO operations in `zio.blocking.blocking`.
If you have a complex program that makes more than one call to `flatMapBlocking`, then it may be worth running *all* of the ZIO-NIO parts using the blocking pool. This can be done by wrapping the effect value with your ZIO-NIO operations in `zio.blocking.blocking`.

If this isn't done, you can end up with the calls using `BlockingOps` running on a thread from the blocking pool, while the other parts run on a thread from the standard pool. This involves an "asynchronous boundary" whever the fiber changes the underlying thread it's running on, which imposes some overheads including a full memory barrier. By using `zio.blocking.blocking` up-front, all the code can run on the same thread from the blocking pool.

Expand All @@ -71,7 +71,7 @@ There are three main styles of channel available: blocking, non-blocking and asy

### Blocking Channels

Easy to use, with a straight-forward operation. The downsides are that you have to use `useBlocking`, which creates a new thread, and will create an additional thread for every forked fiber subsequently created. Essentially you have a blocked thread for every active I/O call, which limits scalability. Also, the additional interrupt handling logic imposes a small overhead.
Easy to use, with a straight-forward operation. The downsides are that you have to use `flatMapBlocking`, which creates a new thread, and will create an additional thread for every forked fiber subsequently created. Essentially you have a blocked thread for every active I/O call, which limits scalability. Also, the additional interrupt handling logic imposes a small overhead.

### Non-Blocking Channels

Expand All @@ -85,6 +85,6 @@ The other issue is that only network channels and pipes support non-blocking mod

Asynchronous channels give us what we want: we don't need a `Selector` to use them, and our thread will never block when we use them.

However, it should be noted that asynchronous file I/O is not currently possible on the JVM. `AsynchronousFileChannel` is performing blocking I/O using a pool of blocked threads, which exactly what `useBlocking` does, and shares the same drawbacks. It may be preferable to use a standard `FileChannel`, as you'll have more visibility and control over what's going on.
However, it should be noted that asynchronous file I/O is not currently possible on the JVM. `AsynchronousFileChannel` is performing blocking I/O using a pool of blocked threads, which exactly what `flatMapBlocking` does, and shares the same drawbacks. It may be preferable to use a standard `FileChannel`, as you'll have more visibility and control over what's going on.

The asynchronous socket channels do *appear* to use non-blocking I/O, although they also have some form of internal thread pool as well. These should scale roughly as well as non-blocking channels. One downside is that there is no asynchronous datagram channel.
15 changes: 7 additions & 8 deletions docs/essentials/charsets.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,23 @@ import zio.nio.channels.FileChannel
import zio.nio.channels._
import zio.nio.file.Path
import zio.stream.ZStream
import zio.blocking.Blocking
import zio.console
import zio.Console
import zio.ZIO

// dump a file encoded in ISO8859 to the console

FileChannel.open(Path("iso8859.txt")).useNioBlockingOps { fileOps =>
val inStream: ZStream[Blocking, Exception, Byte] = ZStream.repeatEffectChunkOption {
FileChannel.open(Path("iso8859.txt")).flatMapNioBlockingOps { fileOps =>
val inStream: ZStream[Any, Exception, Byte] = ZStream.repeatZIOChunkOption {
fileOps.readChunk(1000).asSomeError.flatMap { chunk =>
if (chunk.isEmpty) ZIO.fail(None) else ZIO.succeed(chunk)
}
}

// apply decoding transducer
val charStream: ZStream[Blocking, Exception, Char] =
inStream.transduce(Charset.Standard.iso8859_1.newDecoder.transducer())
val charStream: ZStream[Any, Exception, Char] =
inStream.via(Charset.Standard.iso8859_1.newDecoder.transducer())

console.putStrLn("ISO8859 file contents:") *>
charStream.foreachChunk(chars => console.putStr(chars.mkString))
Console.printLine("ISO8859 file contents:") *>
charStream.runForeachChunk(chars => Console.printLine(chars.mkString))
}
```
Loading
Loading