The following code illustrates blocking an 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 can play with the code here .
Vladimir Bauer 07 Oct '16 at 14:18 2016-10-07 14:18
source share