I\'m trying to create an asynchronous channel and I\'ve been looking at http://golang.org/ref/spec#Making_slices_maps_and_channels.
c := make(chan int, 10)
The following code illustrates the blocking of unbuffered channel:
// to see the diff, change 0 to 1
c := make(chan struct{}, 0)
go func() {
time.Sleep(2 * time.Second)
<-c
}()
start := time.Now()
c <- struct{}{} // block, if channel size is 0
elapsed := time.Since(start)
fmt.Printf("Elapsed: %v\n", elapsed)
You may play with the code here.