title: Go Concurrency Pattern- will this leave hanging goroutines?
body: <p>In Rob Pike's <a href="https://www.youtube.com/watch?v=f6kdp27TYZs" rel="nofollow">Google IO talk</a> on Go Concurrency Patterns, he presented <a href="http://talks.golang.org/2012/concurrency.slide#48" rel="nofollow">this code</a> as an example of how to pick the fastest responder from a number of replica servers:</p>
  
  <pre><code>func First(query string, replicas ...Search) Result {
      c := make(chan Result)
      searchReplica := func(i int) { c &lt;- replicas[i](query) }
      for i := range replicas {
          go searchReplica(i)
      }
      return &lt;-c
  }
  </code></pre>
  
  <p><strong>Question</strong>: Won't this leave N-1 of the replica goroutines blocking on a channel write?</p>
  
  <p>In the discussion after the talk, one of the audience members seems to be asking this question, but got kind of a handy-wavy response. </p>
  
  <p>I'd be inclined to change the 3rd line to something like this:</p>
  
  <pre><code>searchReplica := func(i int) {
     select {
        case c &lt;- replicas[i](query):
        default: // non-blocking write
   }
  }
  </code></pre>