Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jjeffcaii/reactor-go
A golang implementation for reactive-streams.
https://github.com/jjeffcaii/reactor-go
go golang reactive-stream reactive-streams reactivex reactor rxgo rxjava
Last synced: about 14 hours ago
JSON representation
A golang implementation for reactive-streams.
- Host: GitHub
- URL: https://github.com/jjeffcaii/reactor-go
- Owner: jjeffcaii
- License: mit
- Created: 2019-03-07T09:48:31.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-07-19T06:57:26.000Z (over 2 years ago)
- Last Synced: 2024-06-18T17:03:49.215Z (5 months ago)
- Topics: go, golang, reactive-stream, reactive-streams, reactivex, reactor, rxgo, rxjava
- Language: Go
- Homepage: https://jjeffcaii.github.io/reactor-go
- Size: 348 KB
- Stars: 66
- Watchers: 4
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# reactor-go 🚀🚀🚀
![GitHub Workflow Status](https://github.com/jjeffcaii/reactor-go/workflows/Go/badge.svg)
[![codecov](https://codecov.io/gh/jjeffcaii/reactor-go/branch/master/graph/badge.svg)](https://codecov.io/gh/jjeffcaii/reactor-go)
[![GoDoc](https://godoc.org/github.com/jjeffcaii/reactor-go?status.svg)](https://godoc.org/github.com/jjeffcaii/reactor-go)
[![Go Report Card](https://goreportcard.com/badge/github.com/jjeffcaii/reactor-go)](https://goreportcard.com/report/github.com/jjeffcaii/reactor-go)
[![License](https://img.shields.io/github/license/jjeffcaii/reactor-go.svg)](https://github.com/jjeffcaii/reactor-go/blob/master/LICENSE)
[![GitHub Release](https://img.shields.io/github/release-pre/jjeffcaii/reactor-go.svg)](https://github.com/jjeffcaii/reactor-go/releases)> A golang implementation for [reactive-streams](https://www.reactive-streams.org/).
## Install
```sh
go get -u github.com/jjeffcaii/reactor-go
```## Example
### Mono
```go
package mono_testimport (
"context"
"fmt""github.com/jjeffcaii/reactor-go"
"github.com/jjeffcaii/reactor-go/mono"
)func Example() {
gen := func(ctx context.Context, sink mono.Sink) {
sink.Success("World")
}
mono.
Create(gen).
Map(func(input reactor.Any) (output reactor.Any, err error) {
output = "Hello " + input.(string) + "!"
return
}).
DoOnNext(func(v reactor.Any) error {
fmt.Println(v)
return nil
}).
Subscribe(context.Background())
}// Should print
// Hello World!```
### Flux
```go
package flux_testimport (
"context"
"fmt""github.com/jjeffcaii/reactor-go"
"github.com/jjeffcaii/reactor-go/flux"
"github.com/jjeffcaii/reactor-go/scheduler"
)func Example() {
gen := func(ctx context.Context, sink flux.Sink) {
for i := 0; i < 10; i++ {
v := i
sink.Next(v)
}
sink.Complete()
}
done := make(chan struct{})var su reactor.Subscription
flux.Create(gen).
Filter(func(i interface{}) bool {
return i.(int)%2 == 0
}).
Map(func(input reactor.Any) (output reactor.Any, err error) {
output = fmt.Sprintf("#HELLO_%04d", input.(int))
return
}).
SubscribeOn(scheduler.Elastic()).
Subscribe(context.Background(),
reactor.OnSubscribe(func(s reactor.Subscription) {
su = s
s.Request(1)
}),
reactor.OnNext(func(v reactor.Any) error {
fmt.Println("next:", v)
su.Request(1)
return nil
}),
reactor.OnComplete(func() {
close(done)
}),
)
<-done
}
// Should print:
// next: #HELLO_0000
// next: #HELLO_0002
// next: #HELLO_0004
// next: #HELLO_0006
// next: #HELLO_0008
```