-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
174 additions
and
4 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Headline | ||
# reactor-go | ||
|
||
> An awesome project. | ||
> A golang implementation for reactive-streams. |
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,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.
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,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. |
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,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()) | ||
} | ||
|
||
``` |
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,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()) | ||
} | ||
|
||
``` |
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 @@ | ||
# TODO |