Go: Common mistakes: Writing to a chan you're not reading from

When you create a chan using a simple make(chan bool) the chan is incapable of buffering elements or in other terms it has a capicity of zero. A write to a chan blocks if nobody is reading from it... except when you've allocated enough space to buffer elements. This means that the following code for example is a deadlock:

package main

import (
	"fmt"
)

func main() {
	ch1 := make(chan bool)
	ch2 := make(chan bool)
	go func() {
		ch1 <- true
		ch2 <- true
	}()
	fmt.Println(<-ch2)
	fmt.Println(<-ch1)
}

The reason is simply that ch1 <- true blocks because nobody is reading from it because the code is currently trying to read from ch2 and reads (rightfully) block until an element is available. Of course, in this example we can just rearrange the order of reads to make it work but there are other cases where this isn't really feasible. A more complicated example is this:

func main() {
	fmt.Println("Hello, playground")
	
	timer := time.NewTimer(120 * time.Millisecond)
	
	var wg sync.WaitGroup
	res1 := make(chan int)
	res2 := make(chan int)
	wg.Add(2)
	
	wgch := make(chan bool)
	
	go func() {
		wg.Wait()
		wgch < true
	}()
	
	go func() {
		time.Sleep(time.Duration(rand.Int() % 75) * time.Millisecond)
		res1 < 1
		wg.Done()
	}()
	
	go func() {
		time.Sleep(time.Duration(rand.Int() % 75) * time.Millisecond)
		res2 < 2
		wg.Done()
	}()
	
	
	select {
	case _ =  < wgch:
		fmt.Println("done in time")
	case _ = < timer.C:
		fmt.Println("expired")
	}
}

What's wrong with it? Well... it always expires. What's the problem? We create a WaitGroup to wait until all goroutines have finished. The problem again is that we're not reading from the chans res1 and res2 right? Yes. It is. But we obviously can't just read from them because that'd block until the element is available but we want a timeout. We could use a select if we had just one channel but with multiple channels? In this case and in my opinion the easiest solution is to use chans with a capacity of one: make(chan bool, 1).