Skip to content

Instantly share code, notes, and snippets.

@R4wm
Created May 10, 2018 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save R4wm/681ba0d824ad0bbeafe9be5820e2c4e7 to your computer and use it in GitHub Desktop.
Save R4wm/681ba0d824ad0bbeafe9be5820e2c4e7 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"sync"
)
var wg = sync.WaitGroup{}
func main() {
ch := make(chan struct{}, 40)
wg.Add(2)
//sending channel
go func(ch chan<- struct{}) {
println("sending 42 to channel")
ch <- struct{}{}
ch <- struct{}{}
wg.Done()
}(ch)
//receive channel
go func(ch <-chan struct{}) {
fmt.Println(<-ch)
//uncomment to see second element in buffered channel
// fmt.Println(<-ch)
wg.Done()
}(ch)
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment