This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Publish Docs to The NPM Registry (#349)
* prepare docs. * ignore .idea. * update docs. * install zio-sbt-website plugin. * update ci. * generate site workflow. * a commit to triger the ci again. * another commit to run ci.
- Loading branch information
Showing
9 changed files
with
159 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,9 +48,22 @@ jobs: | |
- name: Run tests | ||
run: sbt ++${{ matrix.scala }}! test | ||
|
||
website: | ||
runs-on: ubuntu-20.04 | ||
timeout-minutes: 60 | ||
steps: | ||
- name: Checkout current branch | ||
uses: actions/[email protected] | ||
- name: Setup Scala and Java | ||
uses: olafurpg/setup-scala@v13 | ||
- name: Cache scala dependencies | ||
uses: coursier/cache-action@v6 | ||
- name: Check Document Generation | ||
run: sbt docs/compileDocs | ||
|
||
publish: | ||
runs-on: ubuntu-20.04 | ||
needs: [lint, test] | ||
needs: [lint, test, website] | ||
if: github.event_name != 'pull_request' | ||
steps: | ||
- name: Checkout current branch | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# This file was autogenerated using `zio-sbt` via `sbt generateGithubWorkflow` | ||
# task and should be included in the git repository. Please do not edit | ||
# it manually. | ||
|
||
name: website | ||
|
||
on: | ||
release: | ||
types: [ published ] | ||
|
||
jobs: | ||
publish-docs: | ||
runs-on: ubuntu-20.04 | ||
timeout-minutes: 30 | ||
steps: | ||
- uses: actions/[email protected] | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Scala and Java | ||
uses: olafurpg/setup-scala@v13 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16.x' | ||
registry-url: 'https://registry.npmjs.org' | ||
- name: Publishing Docs to NPM Registry | ||
run: sbt sbt/publishToNpm | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
.sbtopts | ||
.vscode | ||
.lh | ||
.idea | ||
metals.sbt | ||
project/.sbt | ||
project/metals.sbt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
--- | ||
id: index | ||
title: "Introduction to ZIO Interop Reactive Streams" | ||
sidebar_label: "ZIO Interop Reactive Streams" | ||
--- | ||
|
||
This library provides an interoperability layer between ZIO and reactive streams. | ||
|
||
## Reactive Streams `Producer` and `Subscriber` | ||
|
||
**ZIO** integrates with [Reactive Streams](http://reactive-streams.org) by providing conversions from `zio.stream.Stream` to `org.reactivestreams.Publisher` | ||
and from `zio.stream.Sink` to `org.reactivestreams.Subscriber` and vice versa. Simply import `import zio.interop.reactivestreams._` to make the | ||
conversions available. | ||
|
||
## Examples | ||
|
||
First, let's get a few imports out of the way. | ||
|
||
```scala | ||
import org.reactivestreams.example.unicast._ | ||
import zio._ | ||
import zio.interop.reactivestreams._ | ||
import zio.stream._ | ||
``` | ||
|
||
We use the following `Publisher` and `Subscriber` for the examples: | ||
|
||
```scala | ||
val publisher = new RangePublisher(3, 10) | ||
val subscriber = new SyncSubscriber[Int] { | ||
override protected def whenNext(v: Int): Boolean = { | ||
print(s"$v, ") | ||
true | ||
} | ||
} | ||
``` | ||
|
||
### Publisher to Stream | ||
|
||
A `Publisher` used as a `Stream` buffers up to `qSize` elements. If possible, `qSize` should be | ||
a power of two for best performance. The default is 16. | ||
|
||
```scala | ||
val streamFromPublisher = publisher.toZIOStream(qSize = 16) | ||
streamFromPublisher.run(Sink.collectAll[Integer]) | ||
``` | ||
|
||
### Subscriber to Sink | ||
|
||
When running a `Stream` to a `Subscriber`, a side channel is needed for signalling failures. | ||
For this reason `toZIOSink` returns a tuple of a callback and a `Sink`. The callback must be used to signal `Stream` failure. The type parameter on `toZIOSink` is the error type of *the Stream*. | ||
|
||
```scala | ||
val asSink = subscriber.toZIOSink[Throwable] | ||
val failingStream = ZStream.range(3, 13) ++ ZStream.fail(new RuntimeException("boom!")) | ||
ZIO.scoped { | ||
asSink.flatMap { case (signalError, sink) => // FIXME | ||
failingStream.run(sink).catchAll(signalError) | ||
} | ||
} | ||
``` | ||
|
||
### Stream to Publisher | ||
|
||
```scala | ||
val stream = Stream.range(3, 13) | ||
stream.toPublisher.flatMap { publisher => | ||
UIO(publisher.subscribe(subscriber)) | ||
} | ||
``` | ||
|
||
### Sink to Subscriber | ||
|
||
`toSubscriber` returns a `Subscriber` and an `IO` which completes with the result of running the `Sink` or the error if the `Publisher` fails. | ||
A `Sink` used as a `Subscriber` buffers up to `qSize` elements. If possible, `qSize` should be a power of two for best performance. The default is 16. | ||
|
||
```scala | ||
val sink = Sink.collectAll[Integer] | ||
ZIO.scoped { | ||
sink.toSubscriber(qSize = 16).flatMap { case (subscriber, result) => | ||
UIO(publisher.subscribe(subscriber)) *> result | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "@zio.dev/zio-interop-reactivestreams", | ||
"description": "ZIO Interop Reactive Streams Documentation", | ||
"license": "Apache-2.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const sidebars = { | ||
sidebar: [ | ||
"index" | ||
] | ||
}; | ||
|
||
module.exports = sidebars; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters