Created
August 7, 2025 18:02
-
-
Save inkel/a29272aa476dbe2bff1b7e0a5c6a1252 to your computer and use it in GitHub Desktop.
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" | |
| "time" | |
| ) | |
| func main() { | |
| var ( | |
| ch = make(chan int) | |
| out = make(chan int) | |
| ) | |
| go server(ch) | |
| go worker(ch, out) | |
| go notify(out) | |
| time.Sleep(5 * time.Second) | |
| close(ch) | |
| close(out) | |
| } | |
| func server(ch chan<- int) { | |
| for i := range 10 { | |
| ch <- i | |
| } | |
| } | |
| func worker(in <-chan int, out chan<- int) { | |
| for i := range in { | |
| out <- i | |
| } | |
| } | |
| func notify(out <-chan int) { | |
| for i := range out { | |
| fmt.Println(i) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment