https://github.com/transcelestial/chanpiper
A simple interface that implements *-to-many data flow using channels.
https://github.com/transcelestial/chanpiper
channels go golang pubsub
Last synced: 5 months ago
JSON representation
A simple interface that implements *-to-many data flow using channels.
- Host: GitHub
- URL: https://github.com/transcelestial/chanpiper
- Owner: transcelestial
- License: mit
- Created: 2022-04-02T13:11:04.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-04-03T11:13:51.000Z (about 4 years ago)
- Last Synced: 2024-06-21T12:03:09.319Z (about 2 years ago)
- Topics: channels, go, golang, pubsub
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# chanpiper
> A simple interface that implements *-to-many data flow using channels in Go.
[](https://github.com/transcelestial/chanpiper/actions?query=workflow%3ATest)
## Usage
To use `chanpiper` w/o [generics](https://go.dev/doc/tutorial/generics):
```go
package main
import (
"fmt"
"github.com/transcelestial/chanpiper"
)
func main() {
source := make(chan chanpiper.Data)
piper := chanpiper.New(source)
p1 := piper.Pipe()
p2 := piper.Pipe()
go func() {
for data := range p1 {
fmt.Println(data.V)
}
}()
go func() {
for data := range p2 {
fmt.Println(data.V)
}
}()
source <- chanpiper.Data{"ping"}
close(source)
}
```
See the [example](./example_chanpiper_test.go) for a working example.
To use `chanpiper/v2` w/ [generics](https://go.dev/doc/tutorial/generics):
```go
package main
import (
"fmt"
"github.com/transcelestial/chanpiper/v2"
)
func main() {
source := make(chan string)
piper := chanpiper.New(source)
p1 := piper.Pipe()
p2 := piper.Pipe()
go func() {
for data := range p1 {
fmt.Println(data.V)
}
}()
go func() {
for data := range p2 {
fmt.Println(data.V)
}
}()
source <- "ping"
close(source)
}
```
See the [example](./v2/example_chanpiper_test.go) for a working example.
## Contribute
If you wish to contribute, please use the following guidelines:
* Use [conventional commits](https://conventionalcommits.org/)
* Use [effective Go](https://golang.org/doc/effective_go)