code: func (m *Mux) jobDoneCh(jobID string, stop <-chan struct{}) <-chan struct{} {
  	ch := make(chan struct{})
  	go func() {
  		defer close(ch)
  		var started chan struct{}
  		m.jobsMtx.Lock()
  		// check if there is already a WaitGroup
  		wg, ok := m.jobWaits[jobID]
  		if !ok {
  			// if not, check if there is a channel to be notified when one is
  			// created
  			started, ok = m.jobStarts[jobID]
  			if !ok {
  				// if not, make and save the channel
  				started = make(chan struct{})
  				m.jobStarts[jobID] = started
  			}
  		}
  		m.jobsMtx.Unlock()
  
  		if started != nil {
  			// if the wg doesn't exist, wait for it
  			select {
  			case <-started:
  			case <-stop:
  				return
  			}
  			m.jobsMtx.Lock()
  			wg, ok = m.jobWaits[jobID]
  			m.jobsMtx.Unlock()
  			if !ok {
  				// if there is no wg, it was created and deleted before we could
  				// read it, we're done
  				return
  			}
  		}
  
  		// wait for the job to finish
  		wg.Wait()
  	}()
  	return ch
  }
docs: // jobDoneCh returns a channel that is closed when all of the streams we are
  // following from the job have been closed. It will never unblock if the job has
  // already finished.