// WaitService provides a mock function with given fields: ctx, dstate, timeout, recursive, serviceIDs
167910
func (_m *FacadeInterface) WaitService(ctx datastore.Context, dstate service.DesiredState, timeout time.Duration, recursive bool, serviceIDs ...string) error {
	ret := _m.Called(ctx, dstate, timeout, recursive, serviceIDs)

	var r0 error
	if rf, ok := ret.Get(0).(func(datastore.Context, service.DesiredState, time.Duration, bool, ...string) error); ok {
		r0 = rf(ctx, dstate, timeout, recursive, serviceIDs...)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
691983
func (svc *googleService) waitForOperationReady(operation string) error {
	return waitForOperation(OperationTimeout, func() (*googlecloud.Operation, error) {
		return svc.service.ZoneOperations.Get(svc.vm.Project, svc.vm.Zone, operation).Do()
	})
}
1117096
func (p *Controller) Wait(ctx context.Context) error {
	p.logger.Debug("Wait")

	pl, err := p.backend.Get(p.pluginID)
	if err != nil {
		return err
	}

	events, cancel := p.backend.SubscribeEvents(1, plugin.EventDisable{Plugin: pl.PluginObj}, plugin.EventRemove{Plugin: pl.PluginObj}, plugin.EventEnable{Plugin: pl.PluginObj})
	defer cancel()

	if p.signalWaitReady != nil {
		p.signalWaitReady()
	}

	if !p.spec.Disabled != pl.IsEnabled() {
		return errors.New("mismatched plugin state")
	}

	for {
		select {
		case <-ctx.Done():
			return ctx.Err()
		case e := <-events:
			p.logger.Debugf("got event %T", e)

			switch e.(type) {
			case plugin.EventEnable:
				if p.spec.Disabled {
					return errors.New("plugin enabled")
				}
			case plugin.EventRemove:
				return errors.New("plugin removed")
			case plugin.EventDisable:
				if !p.spec.Disabled {
					return errors.New("plugin disabled")
				}
			}
		}
	}
}
420333
func (r *Registry) Wait(id string) time.Duration {
	return r.getOrCreate(id, r.newFunc).Take(1)
}
1253341
func (c *ECS) WaitUntilServicesStable(input *DescribeServicesInput) error {
	return c.WaitUntilServicesStableWithContext(aws.BackgroundContext(), input)
}
75960
func (_m *Facade) WaitSingleService(_a0 *service.Service, _a1 service.DesiredState, _a2 <-chan interface{}) error {
	ret := _m.Called(_a0, _a1, _a2)

	var r0 error
	if rf, ok := ret.Get(0).(func(*service.Service, service.DesiredState, <-chan interface{}) error); ok {
		r0 = rf(_a0, _a1, _a2)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
457630
func (zk *zkf) WaitInstance(ctx datastore.Context, svc *service.Service, instanceID int, checkInstance func(*zks.State, bool) bool, cancel <-chan struct{}) error {
	logger := plog.WithFields(log.Fields{
		"serviceid":   svc.ID,
		"servicename": svc.Name,
		"poolid":      svc.PoolID,
	})

	// get the root-based connection
	rootconn, err := getLocalConnection(ctx, "/")
	if err != nil {
		logger.WithError(err).Debug("Could not acquire root-based connection")
		return err
	}

	// do wait
	errC := make(chan error)
	stop := make(chan struct{})
	go func() {
		errC <- zks.WaitInstance(stop, rootconn, svc.PoolID, svc.ID, instanceID, checkInstance)
	}()

	select {
	case err := <-errC:
		if err != nil {
			logger.WithError(err).Debug("Could not monitor the instance in zookeeper")
			return err
		}
		return err
	case <-cancel:
		close(stop)
		return <-errC
	}
}
1137215
func Wait(ctx context.Context, c *Collector, obj types.ManagedObjectReference, ps []string, f func([]types.PropertyChange) bool) error {
	filter := new(WaitFilter).Add(obj, obj.Type, ps)

	return WaitForUpdates(ctx, c, filter, func(updates []types.ObjectUpdate) bool {
		for _, update := range updates {
			if f(update.ChangeSet) {
				return true
			}
		}

		return false
	})
}
1007936
func (s *Scheduler) waitFor(ctx context.Context, op stackOperation, ss twelvefactor.StatusStream) func(*cloudformation.DescribeStacksInput) error {
	waiter := waiters[op]
	wait := waiter.wait(s.cloudformation)

	return func(input *cloudformation.DescribeStacksInput) error {
		tags := []string{
			fmt.Sprintf("stack:%s", *input.StackName),
		}
		publish(ctx, ss, waiter.startMessage)
		start := time.Now()
		err := wait(input)
		stats.Timing(ctx, fmt.Sprintf("scheduler.cloudformation.%s", op), time.Since(start), 1.0, tags)
		if err == nil {
			publish(ctx, ss, waiter.successMessage)
		}
		return err
	}
}
217002
func (c *ELB) WaitUntilAnyInstanceInService(input *DescribeInstanceHealthInput) error {
	return c.WaitUntilAnyInstanceInServiceWithContext(aws.BackgroundContext(), input)
}
619116
func (s *ReindexService) WaitForCompletion(waitForCompletion bool) *ReindexService {
	s.waitForCompletion = &waitForCompletion
	return s
}
493666
func WaitForService(c kubernetes.Interface, namespace, name string, exist bool, interval, timeout time.Duration) error {
	err := wait.PollImmediate(interval, timeout, func() (bool, error) {
		_, err := c.Core().Services(namespace).Get(name, metav1.GetOptions{})
		switch {
		case err == nil:
			glog.Infof("Service %s in namespace %s found.", name, namespace)
			return exist, nil
		case apierrs.IsNotFound(err):
			glog.Infof("Service %s in namespace %s disappeared.", name, namespace)
			return !exist, nil
		case !IsRetryableAPIError(err):
			glog.Info("Non-retryable failure while getting service.")
			return false, err
		default:
			glog.Infof("Get service %s in namespace %s failed: %v", name, namespace, err)
			return false, nil
		}
	})
	if err != nil {
		stateMsg := map[bool]string{true: "to appear", false: "to disappear"}
		return fmt.Errorf("error waiting for service %s/%s %s: %v", namespace, name, stateMsg[exist], err)
	}
	return nil
}
128472
func (_m *ServiceStateManager) WaitScheduled(tenantID string, serviceIDs ...string) {
	_m.Called(tenantID, serviceIDs)
}
1113210
func (rc *rawConn) waitOperation(projectID string, op *compute.Operation, attempts utils.AttemptStrategy) error {
	// TODO(perrito666) 2016-05-02 lp:1558657
	started := time.Now()
	logger.Infof("GCE operation %q, waiting...", op.Name)
	for a := attempts.Start(); a.Next(); {
		if op.Status == StatusDone {
			break
		}

		var err error
		op, err = rc.checkOperation(projectID, op)
		if err != nil {
			return errors.Trace(err)
		}
	}
	if op.Status != StatusDone {
		// lp:1558657
		err := errors.Errorf("timed out after %d seconds", time.Now().Sub(started)/time.Second)
		return waitError{op, err}
	}
	if op.Error != nil {
		for _, err := range op.Error.Errors {
			logger.Errorf("GCE operation error: (%s) %s", err.Code, err.Message)
		}
		return waitError{op, nil}
	}

	logger.Infof("GCE operation %q finished", op.Name)
	return nil
}
446975
func (n *Node) waitRole(ctx context.Context, role string) error {
	n.roleCond.L.Lock()
	if role == n.role {
		n.roleCond.L.Unlock()
		return nil
	}
	finishCh := make(chan struct{})
	defer close(finishCh)
	go func() {
		select {
		case <-finishCh:
		case <-ctx.Done():
			// call broadcast to shutdown this function
			n.roleCond.Broadcast()
		}
	}()
	defer n.roleCond.L.Unlock()
	for role != n.role {
		n.roleCond.Wait()
		select {
		case <-ctx.Done():
			return ctx.Err()
		default:
		}
	}

	return nil
}
7933
func WaitService(cancel <-chan struct{}, conn client.Connection, poolID, serviceID string, checkCount func(count int) bool, checkState func(s *State, exists bool) bool) error {
	basepth := ""
	if poolID != "" {
		basepth = path.Join("/pools", poolID)
	}
	pth := path.Join(basepth, "/services", serviceID)

	logger := plog.WithFields(log.Fields{
		"serviceid": serviceID,
		"zkpath":    pth,
	})

	done := make(chan struct{})
	defer func() { close(done) }()
	for {

		// clean any bad service states
		if err := CleanServiceStates(conn, poolID, serviceID); err != nil {
			return err
		}

		// get the list of states
		ch, ev, err := conn.ChildrenW(pth, done)
		if err != nil {

			logger.WithError(err).Debug("Could not watch states for service")

			// TODO: wrap error?
			return err
		}

		// make sure the count satisfies the requirements
		if checkCount(len(ch)) {
			ok := true

			for _, stateID := range ch {
				st8log := logger.WithField("stateid", stateID)

				// parse the state id and set up the request
				hostID, _, instanceID, err := ParseStateID(stateID)
				if err != nil {

					// This should never happen, but handle it
					st8log.WithError(err).Error("Invalid state id while monitoring service")
					return err
				}

				req := StateRequest{
					PoolID:     poolID,
					HostID:     hostID,
					ServiceID:  serviceID,
					InstanceID: instanceID,
				}

				// wait for the state to satisfy the requirements
				if _, err := MonitorState(cancel, conn, req, checkState); err != nil {
					st8log.WithError(err).Debug("Stopped monitoring state")

					// return if cancel was triggered
					select {
					case <-cancel:
						return nil
					default:
					}

					ok = false
					break
				}
			}

			// if all of the requirements are satisfied, return
			if ok {
				return nil
			}
		}

		// otherwise, wait for the number of states to change
		select {
		case <-ev:
		case <-cancel:
			return nil
		}
		close(done)
		done = make(chan struct{})
	}
}
484024
func (rw *RetryWaiter) wait() <-chan struct{} {
	waitTime := rw.calculateWait()
	ch := make(chan struct{})
	if waitTime > 0 {
		time.AfterFunc(waitTime, func() { close(ch) })
	} else {
		// if there should be 0 wait time then we ensure
		// that the chan will be immediately selectable
		close(ch)
	}
	return ch
}