Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jjeffcaii committed Jul 25, 2019
1 parent f497379 commit ec825db
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Headline
# reactor-go

> An awesome project.
> A golang implementation for reactive-streams.
25 changes: 25 additions & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!-- docs/_sidebar.md -->

- Getting started
- [Intrudction](introduction.md)
- [Quick start](quickstart.md)

- Mono
- [Initialization](mono/create.md)
- Operators
- [Filter](todo.md)
- [Map](todo.md)
- [FlatMap](todo.md)
- [DoOnNext](todo.md)
- [DoOnComplete](todo.md)
- [DoOnSubscribe](todo.md)
- [DoOnError](todo.md)
- [DoOnCancel](todo.md)
- [DoFinally](todo.md)
- [DoOnDiscard](todo.md)
- [DelayElement](todo.md)
- [SwitchIfEmpty](todo.md)
- [SubscribeOn](todo.md)

- Flux
- [Initialization](flux/create.md)
Empty file added docs/flux/create.md
Empty file.
6 changes: 4 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
<script>
window.$docsify = {
name: 'reactor-go',
repo: 'https://github.com/jjeffcaii/reactor-go',
coverpage: true
repo: 'https://github.com/jjeffcaii/reactor-go/',
coverpage: true,
loadSidebar: true
}
</script>
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
</body>
</html>
5 changes: 5 additions & 0 deletions docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Introduction
Reactor is an implementation of the Reactive Programming paradigm, which can be summed up as:
> Reactive programming is an asynchronous programming paradigm concerned with data streams and the propagation of change. This means that it becomes possible to express static (e.g. arrays) or dynamic (e.g. event emitters) data streams with ease via the employed programming language(s).<br><small>— https://en.wikipedia.org/wiki/Reactive_programming</small>
`reactor-go` is a clone of [reactor-core](https://github.com/reactor/reactor-core). It retains most of the reactor-core APIs.
66 changes: 66 additions & 0 deletions docs/mono/create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Initialization
Initialize a `Mono` publisher is easy.

## Just
Use `Just` to wrap an existing target.

``` go
package main

import "github.com/jjeffcaii/reactor-go/mono"

func main() {
mono.Just("Hello World!")
}
```

## Create
Use `Create` to create a new `Mono`.<br/>
Mono is **LAZY** and nothing happens unless you call `Subscribe`!

``` go
package main

import (
"context"
"errors"

"github.com/jjeffcaii/reactor-go/mono"
)

func main() {
mono.Create(func(ctx context.Context, s mono.Sink) {
// Do something and call Success.
s.Success("Hello World!")
})
mono.Create(func(ctx context.Context, s mono.Sink) {
// Do something but failed.
s.Error(errors.New("something bad"))
})
}
```

## Delay
Create a Mono which delays an `int64` by a given duration. A delayed Mono will be scheduled asynchronously.<br/>
In example below, we call `Block` to block result in current coroutine. So it should print `Bingo!!!` after 3 seconds.

``` go
package main

import (
"context"
"fmt"
"time"

"github.com/jjeffcaii/reactor-go/mono"
)

func main() {
mono.Delay(3 * time.Second).
DoOnNext(func(v interface{}) {
fmt.Println("Bingo!!!")
}).
Block(context.Background())
}

```
71 changes: 71 additions & 0 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Quick Start

## Installation
It is recommended to install `reactor-go` as a [Go module](https://github.com/golang/go/wiki/Modules).

``` shell
$ go get -u github.com/jjeffcaii/reactor-go
$ go get -u github.com/jjeffcaii/[email protected]
```

## Imports
We offer `mono` and `flux` package for most features. First you need import these packages.

``` go
import (
"github.com/jjeffcaii/reactor-go"
"github.com/jjeffcaii/reactor-go/mono"
"github.com/jjeffcaii/reactor-go/flux"
)
```

## Mono
Here's a tiny example which show how mono API works. It'll print a `Hello World!` string.

``` go
package main

import (
"context"
"fmt"

"github.com/jjeffcaii/reactor-go/mono"
)

func main() {
mono.Just("World").
Map(func(v interface{}) interface{} {
return fmt.Sprintf("Hello %s", v)
}).
DoOnNext(func(v interface{}) {
fmt.Println(v)
}).
Subscribe(context.Background())
}
```

## Flux
Here's a tiny example which show how flux API works. It'll print `Hello Tom!`, `Hello Jerry!` and `Hello Tux!`.

``` go
package main

import (
"context"
"fmt"

"github.com/jjeffcaii/reactor-go/flux"
)

func main() {
flux.Just("Tom", "Jerry", "Tux").
Map(func(v interface{}) interface{} {
return fmt.Sprintf("Hello %d!", v.(int))
}).
DoOnNext(func(v interface{}) {
fmt.Println(v)
}).
Subscribe(context.Background())
}

```
1 change: 1 addition & 0 deletions docs/todo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TODO

0 comments on commit ec825db

Please sign in to comment.