Skip to content

Instantly share code, notes, and snippets.

@joeke80215
Last active October 12, 2022 00:38
Show Gist options
  • Save joeke80215/995b63c623b091dac0fc3d900e768bae to your computer and use it in GitHub Desktop.
Save joeke80215/995b63c623b091dac0fc3d900e768bae to your computer and use it in GitHub Desktop.
golang fanout example
package main
import (
"fmt"
)
func testP(in <-chan string) {
for v := range in {
fmt.Println(v)
}
fmt.Println("Done")
}
func fanout(outs ...chan<- string) {
for _, out := range outs {
out <- "test channel"
close(out)
}
}
func main() {
c1 := make(chan string)
c2 := make(chan string)
c3 := make(chan string)
blockC := make(chan struct{})
go testP(c1)
go testP(c2)
go testP(c3)
fanout(c1, c2, c3)
<-blockC
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment