Created
May 10, 2018 06:10
-
-
Save R4wm/681ba0d824ad0bbeafe9be5820e2c4e7 to your computer and use it in GitHub Desktop.
This file contains 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" | |
"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