title: go - How to use golang goroutine, select and if statement to return?
body: <p>I'm trying to make a "if" statement in goroutine.
  Question: how to make 10 from 10?</p>
  
  <pre><code>var jr = make(chan int, 10)
  var clients = 10 // The number of clients varies with time.
  
  func rpcMethod(num int) {
      time.Sleep(time.Duration(rand.Intn(int(time.Second))))
      jr &lt;- num
  }
  
  func postHandler(num int) {
      // wait RPC data
      for {
          select {
          case msg := &lt;-jr:
              {
                  if msg == num {
                      fmt.Println(num, "hello from", msg)
                      return
                  }
              }
          }
      }
  }
  
  func main() {
      for i := 0; i &lt; clients; i++ {
          go postHandler(i)
          go rpcMethod(i)
      }
      fmt.Scanln()
  }
  </code></pre>
  
  <h2>Result 2/10</h2>
  
  <ul>
  <li>5 hello from 5</li>
  <li>2 hello from 2</li>
  </ul>