Last active
October 12, 2022 00:38
-
-
Save joeke80215/995b63c623b091dac0fc3d900e768bae to your computer and use it in GitHub Desktop.
golang fanout example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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