Skip to content

A simple interface that implements *-to-many data flow using channels.

License

Notifications You must be signed in to change notification settings

transcelestial/chanpiper

Repository files navigation

chanpiper

A simple interface that implements *-to-many data flow using channels in Go.

GitHub Workflow Status

Usage

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.

Contribute

If you wish to contribute, please use the following guidelines:

About

A simple interface that implements *-to-many data flow using channels.

Topics

Resources

License

Stars

Watchers

Forks

Languages