// Wait4Scheduled blocks until either there are n or more scheduled events, or
// the timeout elapses. It returns true if the wait condition has been met
// before the timeout expired, false otherwise.
437715
func Wait4Scheduled(count int, timeout time.Duration) bool {
	return provider.Wait4Scheduled(count, timeout)
}
400647
func WaitSelected(sel interface{}, opts ...QueryOption) Action {
	return Query(sel, append(opts, NodeSelected)...)
}
1133678
func (w *WindowedSchedule) Wait(last time.Time) Response {
	// If within the window we wait our interval and return
	// otherwise we exit with a completed state.
	var m uint

	if (last == time.Time{}) {
		// the first waiting in cycles, so
		// set the `stopOnTime` determining the right-window boundary
		w.setStopOnTime()
	}

	// Do we even have a specific start time?
	if w.StartTime != nil {
		// Wait till it is time to start if before the window start
		if time.Now().Before(*w.StartTime) {
			wait := w.StartTime.Sub(time.Now())
			logger.WithFields(log.Fields{
				"_block":         "windowed-wait",
				"sleep-duration": wait,
			}).Debug("Waiting for window to start")
			time.Sleep(wait)
		}
	}

	// Do we even have a stop time?
	if w.stopOnTime != nil {
		if time.Now().Before(*w.stopOnTime) {
			logger.WithFields(log.Fields{
				"_block":           "windowed-wait",
				"time-before-stop": w.stopOnTime.Sub(time.Now()),
			}).Debug("Within window, calling interval")

			m, _ = waitOnInterval(last, w.Interval)

			// check if the schedule should be ended after waiting on interval
			if time.Now().After(*w.stopOnTime) {
				logger.WithFields(log.Fields{
					"_block": "windowed-wait",
				}).Debug("schedule has ended")
				w.state = Ended
			}
		} else {
			logger.WithFields(log.Fields{
				"_block": "windowed-wait",
			}).Debug("schedule has ended")
			w.state = Ended
			m = 0
		}
	} else {
		// This has no end like a simple schedule
		m, _ = waitOnInterval(last, w.Interval)

	}
	return &WindowedScheduleResponse{
		state:    w.GetState(),
		missed:   m,
		lastTime: time.Now(),
	}
}
829999
func (r *remoteSubsystem) Wait() error {
	var lastErr error

	for i := 0; i < 3; i++ {
		select {
		case err := <-r.errorCh:
			if err != nil && err != io.EOF {
				r.log.Warnf("Connection problem: %v %T", trace.DebugReport(err), err)
				lastErr = err
			}
		case <-r.ctx.Done():
			lastErr = trace.ConnectionProblem(nil, "context is closing")
		}
	}

	// emit an event to the audit log with the result of execution
	r.emitAuditEvent(lastErr)

	return lastErr
}
573695
func (s *TasksGetTaskService) WaitForCompletion(waitForCompletion bool) *TasksGetTaskService {
	s.waitForCompletion = &waitForCompletion
	return s
}
789452
func (p *pendingPlan) Wait() (*structs.PlanResult, error) {
	err := <-p.errCh
	return p.result, err
}
1004806
func (p *Pod) WaitFinished(ctx context.Context) error {
	f := func() bool {
		switch err := p.TrySharedLock(); err {
		case nil:
			// the pod is now locked successfully, hence one of the running phases passed.
			// continue with unlocking the pod immediately below.
		case lock.ErrLocked:
			// pod is still locked, hence we are still in a running phase.
			// i.e. in pepare, run, exitedGarbage, garbage state.
			return false
		default:
			// some error occurred, bail out.
			return true
		}

		// unlock immediately
		if err := p.Unlock(); err != nil {
			return true
		}

		if err := p.refreshState(); err != nil {
			return true
		}

		// if we're in the gap between preparing and running in a split prepare/run-prepared usage, take a nap
		if p.isPrepared {
			time.Sleep(time.Second)
		}

		return p.IsFinished()
	}

	return retry(ctx, f, 100*time.Millisecond)
}
1302220
func (tt *timeoutThread) waitForEntry(e *entry) bool {
	windowExceeded := time.NewTimer(time.Until(e.deadline))
	defer windowExceeded.Stop()

	select {
	// a) Always check these channels, regardless of the state.
	case <-tt.maxDuration.C:
		// Max duration is up. Stop buffering. Do not error out entries explicitly.
		tt.sb.stopBufferingDueToMaxDuration()
		return true
	case <-tt.stopChan:
		// Failover ended before timeout. Do nothing.
		return true
	// b) Entry-specific checks.
	case <-e.done:
		// Entry was drained or evicted. Get the next entry.
		return false
	// NOTE: We're not waiting for e.bufferCtx here (which triggers when the
	// request was externally aborted e.g. due to context canceled) because then
	// this thread would race with the request thread which runs
	// shardBuffer.remove(). Instead, remove() will notify us here eventually by
	// closing "e.done".
	case <-windowExceeded.C:
		// Entry expired. Evict it and then get the next entry.
		tt.sb.evictOldestEntry(e)
		return false
	}
}
388936
func UpgradeWait(wait bool) UpdateOption {
	return func(opts *options) {
		opts.updateReq.Wait = wait
	}
}
1081352
func WithWait(d time.Duration) Option {
	return func(l *Loader) {
		l.wait = d
	}
}
275295
func (h *Handler) WaitForReady() bool {
	// there is no ready func configured, so we return immediately
	if h.readyFunc == nil {
		return true
	}

	timeout := time.After(timeToWaitForReady)
	for !h.readyFunc() {
		select {
		case <-time.After(100 * time.Millisecond):
		case <-timeout:
			return h.readyFunc()
		}
	}
	return true
}
352723
func (c *Client) WaitForClusterAvailable(retries int, retryInterval time.Duration) (bool, error) {
	for i := 0; i < retries; i++ {
		if i > 0 {
			klog.V(1).Infof("[etcd] Waiting %v until next retry\n", retryInterval)
			time.Sleep(retryInterval)
		}
		klog.V(2).Infof("[etcd] attempting to see if all cluster endpoints (%s) are available %d/%d", c.Endpoints, i+1, retries)
		resp, err := c.ClusterAvailable()
		if err != nil {
			switch err {
			case context.DeadlineExceeded:
				klog.V(1).Infof("[etcd] Attempt timed out")
			default:
				klog.V(1).Infof("[etcd] Attempt failed with error: %v\n", err)
			}
			continue
		}
		return resp, nil
	}
	return false, errors.New("timeout waiting for etcd cluster to be available")
}
619116
func (s *ReindexService) WaitForCompletion(waitForCompletion bool) *ReindexService {
	s.waitForCompletion = &waitForCompletion
	return s
}
35544
func (c *Conn) WaitUntilReady(ctx context.Context) error {
	err := c.waitForPreviousCancelQuery(ctx)
	if err != nil {
		return err
	}
	return c.ensureConnectionReadyForQuery()
}
270055
func (api *API) WaitUntilDeleted(in ApiInstance) error {
	var err error
	for in != nil {
		_, err = in.GetState()
		if err != nil {
			if apiError, ok := err.(ApiError); ok && apiError.httpStatusCode == http.StatusNotFound {
				return nil
			} else {
				return err
			}
		}
		time.Sleep(5 * time.Second)
	}
	return nil
}
192092
func (js *JobsService) ListScheduled(ctx context.Context) (jobs []*JobSchedule, resp *APIResponse, err error) {
	j := &JobScheduleResponse{}
	_, resp, err = js.client.getAction(ctx, &APIClientRequest{
		Path:         "jobs/scheduled.xml",
		ResponseBody: j,
		ResponseType: responseTypeXML,
	})
	jobs = j.Jobs

	return
}
362262
func (b *build) cancelScheduled(q *BuildQueue) int {
	numBuilds := b.numFolded()

	metrics.BuildQueueEntries.With(map[string]string{
		metrics.LabelBuildQueueName: q.name,
		metrics.LabelBuildState:     metrics.BuildStateWaiting,
	}).Sub(float64(numBuilds))

	b.reportStatus(q, false)

	return numBuilds
}