code: func waitForUnitStates(units []string, js job.JobState, maxAttempts int, out io.Writer) chan error {
  	errchan := make(chan error)
  	var wg sync.WaitGroup
  	for _, name := range units {
  		wg.Add(1)
  		go checkUnitState(name, js, maxAttempts, out, &wg, errchan)
  	}
  
  	go func() {
  		wg.Wait()
  		close(errchan)
  	}()
  
  	return errchan
  }
docs: // waitForUnitStates polls each of the indicated units until each of their
  // states is equal to that which the caller indicates, or until the
  // polling operation times out. waitForUnitStates will retry forever, or
  // up to maxAttempts times before timing out if maxAttempts is greater
  // than zero. Returned is an error channel used to communicate when
  // timeouts occur. The returned error channel will be closed after all
  // polling operation is complete.