title: Changing channel from unbuffered to buffered prevents goroutine from running
body: <p>Here is an exercise using channels and select in a goroutine.  If the disconnect channel is changed to a buffered channel the goroutine doesn't run at all.</p>
  <p>Why does changing from an unbuffered to a buffered channel prevent running the goroutine?</p>
  <pre><code>func SelectDemo(wg *sync.WaitGroup) {
  
      messageCh := make(chan int, 10)
      disconnectCh := make(chan struct{})
      //  go routine won't run if channel is buffered
      //disconnectCh := make(chan struct{}, 1)
  
      defer close(messageCh)
      defer close(disconnectCh)
      go func() {
          fmt.Println(&quot;  goroutine&quot;)
          wg.Add(1)
          for {
              select {
              case v := &lt;-messageCh:
                  fmt.Println(v)
              case &lt;-disconnectCh:
                  fmt.Println(&quot;  disconnectCh&quot;)
                  //  empty the buffered channel before exiting
                  for {
                      select {
                      case v := &lt;-messageCh:
                          fmt.Println(v)
                      default:
                          fmt.Println(&quot;  disconnection, return&quot;)
                          wg.Done()
                          return
                      }
                  }
              }
          }
      }()
  
      fmt.Println(&quot;Sending ints&quot;)
      for i := 0; i &lt; 10; i++ {
          messageCh &lt;- i
      }
  
      fmt.Println(&quot;Sending done&quot;)
      disconnectCh &lt;- struct{}{}
  }
  </code></pre>
  <p>Here's the code to call the function from main.  I use the wait group to assure that the goroutine completes before the program exits:</p>
  <pre><code>wg := sync.WaitGroup{}
  ch09.SelectDemo(&amp;wg)
  wg.Wait()
  </code></pre>