title: How to implement a timeout when using sync.WaitGroup.wait?
body: <p>I have come across a situation that i want to trace some goroutine to sync on a specific point, for example when all the urls are fetched. Then, we can put them all and show them in specific order. </p>
  
  <p>I think this is the <strong>barrier</strong> comes in. It is in <code>go</code> with <code>sync.WaitGroup</code>. However, in real situation that we can not make sure that all the fetch operation will succeed in a short time. So, i want to introduce a timeout when <code>wait</code> for the fetch operations.</p>
  
  <p>I am a newbie to <code>Golang</code>, so can someone give me some advice?</p>
  
  <hr>
  
  <p>What i am looking for is like this:</p>
  
  <pre><code>   wg := &amp;sync.WaigGroup{}
     select {
     case &lt;-wg.Wait():
     // All done!
     case &lt;-time.After(500 * time.Millisecond):
     // Hit timeout.
     }
  </code></pre>
  
  <p>I know <code>Wait</code> do not support <code>Channel</code>.</p>