code: func (d *Deployment) Wait(id string, timeout time.Duration, log log15.Logger) error {
  	timeoutCh := time.After(timeout)
  	for {
  		actual := 0
  		select {
  		case event, ok := <-d.events:
  			if !ok {
  				return fmt.Errorf("service stream closed unexpectedly: %s", d.stream.Err())
  			}
  			if event.Kind == discoverd.EventKindServiceMeta {
  				deploymentMeta, err := d.decode(event.ServiceMeta)
  				if err != nil {
  					return err
  				}
  				log.Info("got service meta event", "state", deploymentMeta)
  				if deploymentMeta.ID == id {
  					actual = 0
  					for _, state := range deploymentMeta.States {
  						if state == DeploymentStateDone {
  							actual++
  						}
  					}
  					if actual == d.jobCount {
  						return nil
  					}
  				} else {
  					log.Warn("ignoring service meta even with wrong ID", "expected", id, "got", deploymentMeta.ID)
  				}
  
  			}
  		case <-timeoutCh:
  			return fmt.Errorf("timed out waiting for discoverd deployment (expected=%d actual=%d)", d.jobCount, actual)
  		}
  	}
  }
docs: // Wait waits for an expected number of "done" addresses in the service metadata