title: How does select work when multiple channels are involved?
body: <p>I found when using select on multiple non buffered channels like</p>
  
  <pre><code>select {
  case &lt;- chana:
  case &lt;- chanb:
  }
  </code></pre>
  
  <p>Even when both channels have data, but when processing this select,
  the call that falls in case chana and case chanb is not balanced. </p>
  
  <pre><code>package main
  
  import (
      "fmt"
      _ "net/http/pprof"
      "sync"
      "time"
  )
  
  func main() {
      chana := make(chan int)
      chanb := make(chan int)
  
      go func() {
          for i := 0; i &lt; 1000; i++ {
              chana &lt;- 100 * i
          }
      }()
  
      go func() {
          for i := 0; i &lt; 1000; i++ {
              chanb &lt;- i
          }
      }()
  
      time.Sleep(time.Microsecond * 300)
  
      acount := 0
      bcount := 0
      wg := sync.WaitGroup{}
      wg.Add(1)
      go func() {
          for {
              select {
              case &lt;-chana:
                  acount++
              case &lt;-chanb:
                  bcount++
              }
              if acount == 1000 || bcount == 1000 {
                  fmt.Println("finish one acount, bcount", acount, bcount)
                  break
              }
          }
          wg.Done()
      }()
  
      wg.Wait()
  }
  </code></pre>
  
  <p>Run this demo, when one of the chana,chanb finished read/write, the other may remain 999-1 left.</p>
  
  <p>Is there any method to ensure the balance?</p>
  
  <p>found related topic<br>
  <a href="https://stackoverflow.com/questions/19865194/golang-channels-select-statement">golang-channels-select-statement</a></p>