A simple interface that implements *-to-many data flow using channels in Go.
To use chanpiper
w/o generics:
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 for a working example.
To use chanpiper/v2
w/ generics:
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 for a working example.
If you wish to contribute, please use the following guidelines:
- Use conventional commits
- Use effective Go