title: Determining all workers are done
body: <p>Following <a href="http://marcio.io/2015/07/handling-1-million-requests-per-minute-with-golang/" rel="nofollow noreferrer">Marcio's thread pool implementation</a> is it possible to determine when all work is done?</p>
  
  <p>Waiting for the JobQueue to empty is trivial:</p>
  
  <pre><code>// Wait for the job queue to clear
  for len(JobQueue) &gt; 0 {
      // Just wait
  }
  </code></pre>
  
  <p>However after that there might still be goroutines waiting for workers, or workers have not unfinished all tasks:</p>
  
  <pre><code>func (d *Dispatcher) dispatch() {
      for {
          select {
          case job := &lt;-JobQueue:
              // a job request has been received
              go func(job Job) {
                  // try to obtain a worker job channel that is available.
                  // this will block until a worker is idle
                  jobChannel := &lt;-d.WorkerPool
  
                  // dispatch the job to the worker job channel
                  jobChannel &lt;- job
              }(job)
          }
      }
  }
  </code></pre>
  
  <p>What's the best approach to this? Add a WaitGroup to the dispatcher, and a method for querying the status of the WaitGroup? Any pointers towards this would be appreciated.</p>