Skip to content

Instantly share code, notes, and snippets.

@Israel-Miles
Created September 27, 2021 15:49
Show Gist options
  • Save Israel-Miles/5152b77475865a5a449bafb0457b707d to your computer and use it in GitHub Desktop.
Save Israel-Miles/5152b77475865a5a449bafb0457b707d to your computer and use it in GitHub Desktop.
func main() {
var wg sync.WaitGroup
channel := make(chan int)
wg.Add(2)
go sendToChannel(channel, &wg)
go receiveFromChannel(channel, &wg)
wg.Wait()
}
func sendToChannel(ch chan<- int, wg *sync.WaitGroup) {
defer wg.Done()
for i := 0; i < 10; i++ {
ch <- i
}
close(ch)
}
func receiveFromChannel(ch <-chan int, wg *sync.WaitGroup) {
defer wg.Done()
for msg := range ch {
fmt.Println(msg)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment