// Wait for the current value of backoff
427716
func (eb exponentialBackoff) wait() {
	time.Sleep(eb.currentDelay)
	eb.currentDelay = eb.b.Duration()
}
194569
func wait() {
	const maxWait = 1 * time.Minute

	now := time.Now().UTC()
	mu.Lock()
	wait := getWaitTime(now, maxWait)
	mu.Unlock()

	time.Sleep(wait)

	interval := 500 * time.Millisecond
	if wait == maxWait {
		interval = maxWait
	}

	mu.Lock()
	defer mu.Unlock()
	if now.Before(nextProvision) {
		nextProvision = nextProvision.Add(interval)
		return
	}
	now = time.Now().UTC()
	nextProvision = now.Add(interval)
}
298541
func Backoff(operation func() (*Response, error), options ...Option) error {
	// Defaults
	opts := Options{
		maxRetries:      defaultMaxRetries,
		waitTime:        defaultWaitTime,
		maxWaitTime:     defaultMaxWaitTime,
		retryConditions: []RetryConditionFunc{},
	}

	for _, o := range options {
		o(&opts)
	}

	var (
		resp *Response
		err  error
	)
	base := float64(opts.waitTime)        // Time to wait between each attempt
	capLevel := float64(opts.maxWaitTime) // Maximum amount of wait time for the retry
	for attempt := 0; attempt < opts.maxRetries; attempt++ {
		resp, err = operation()

		var needsRetry bool
		var conditionErr error
		for _, condition := range opts.retryConditions {
			needsRetry, conditionErr = condition(resp)
			if needsRetry || conditionErr != nil {
				break
			}
		}

		// If the operation returned no error, there was no condition satisfied and
		// there was no error caused by the conditional functions.
		if err == nil && !needsRetry && conditionErr == nil {
			return nil
		}
		// Adding capped exponential backup with jitter
		// See the following article...
		// http://www.awsarchitectureblog.com/2015/03/backoff.html
		temp := math.Min(capLevel, base*math.Exp2(float64(attempt)))
		ri := int(temp / 2)
		if ri <= 0 {
			ri = 1<<31 - 1 // max int for arch 386
		}
		sleepDuration := time.Duration(math.Abs(float64(ri + rand.Intn(ri))))

		if sleepDuration < opts.waitTime {
			sleepDuration = opts.waitTime
		}
		time.Sleep(sleepDuration)
	}

	return err
}
924618
func Wait(b bool) Option {
	return func(o *Options) {
		if o.Context == nil {
			o.Context = context.Background()
		}
		o.Context = context.WithValue(o.Context, "wait", b)
	}
}
12437
func (p *Provider) wait() {
	// Compute the backoff time
	backoff := p.backoffDuration()

	// Setup a wait timer
	var wait <-chan time.Time
	if backoff > 0 {
		jitter := time.Duration(rand.Uint32()) % backoff
		wait = time.After(backoff + jitter)
	}

	// Wait until timer or shutdown
	select {
	case <-wait:
	case <-p.shutdownCh:
	}
}
596411
func (w *Wrapped) Wait() error {
	w.once.Do(w.init)
	w.cancelLock.Lock()
	defer w.cancelLock.Unlock()

	// If we don't have a result yet, wait for that
	if !w.resultSet {
		w.cancelCond.Wait()
	}

	// Return the result
	return w.resultErr
}
542222
func (c *Client) Wait() string {
	waitC := make(chan string, 1)
	var ch chan<- string = waitC

	select {
	case <-c.closing:
	case c.mounted <- ch:
	}

	select {
	case <-c.closing:
	case s := <-waitC:
		return s
	}

	return ""
}
261577
func (sem *Sem) Wait() error {
	ret := int(C.SDL_SemWait(sem.cptr()))
	if ret != 0 {
		return GetError()
	}
	return nil
}
1086906
func (i *InParallel) Wait() error {
	i.wg.Wait()
	obj := i.pool.Get()
	if err, ok := obj.(error); ok {
		return err
	}
	return nil
}
1248953
func (d *decompressor) wait() (Block, error) {
	d.wg.Wait()
	blk := d.blk
	d.blk = nil
	return blk, d.err
}
1018738
func (rs *Result) Wait() {
	rs.consolidator.Record(rs.query)
	rs.executing.RLock()
}
217527
func (s semaphore) wait(ctx context.Context) error {
	// Always check Err first. "select" randomly selects a channel when both
	// channels are available, and we want to prioritize cancelation.
	if err := ctx.Err(); err != nil {
		return err
	}
	select {
	case <-ctx.Done():
		// Err() is guaranteed to be non-nil.
		return ctx.Err()
	case <-s:
		/*
			// Do a last check, just in case. It makes things slightly slower but
			// reduces the chance of race condition with having a spurious item running
			// after cancelation.
			if err := ctx.Err(); err != nil {
				s.signal()
				return err
			}
		*/
		return nil
	}
}
605191
func (p *localPrevAlloc) Wait(ctx context.Context) error {
	p.waitingLock.Lock()
	p.waiting = true
	p.waitingLock.Unlock()
	defer func() {
		p.waitingLock.Lock()
		p.waiting = false
		p.waitingLock.Unlock()
	}()

	defer p.prevListener.Close()

	// Don't bother blocking for updates from the previous alloc if it has
	// already terminated.
	if p.prevStatus.Terminated() {
		p.logger.Trace("previous allocation already terminated")
		return nil
	}

	// Block until previous alloc exits
	p.logger.Debug("waiting for previous alloc to terminate")
	for {
		select {
		case prevAlloc, ok := <-p.prevListener.Ch():
			if !ok || prevAlloc.Terminated() {
				return nil
			}
		case <-ctx.Done():
			return ctx.Err()
		}
	}
}
117992
func (s *Service) wait() {
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, syscall.SIGTERM, os.Kill)
	select {
	case sig := <-c:
		BootPrintln("[service] got signal:", sig)
	case <-s.stopper:
		BootPrintln("[service] app stop")
	}
	s.stop()
}
290475
func (c *Cmd) Wait() error {
	<-c.exitCh

	c.Lock()
	defer c.Unlock()

	if c.err != nil || c.exitStatus != 0 {
		return &ExitError{
			Command:    c.Command,
			ExitStatus: c.exitStatus,
			Err:        c.err,
		}
	}

	return nil
}
1022526
func (cond *TimeoutCond) Wait(ctx context.Context) bool {
	cond.addWaiter()
	//copy signal in lock, avoid data race with Interrupt
	ch := cond.signal
	//wait should unlock mutex,  if not will cause deadlock
	cond.L.Unlock()
	defer cond.removeWaiter()
	defer cond.L.Lock()

	select {
	case _, ok := <-ch:
		return !ok
	case <-ctx.Done():
		return false
	}
}
1016600
func (process *Process) waitBackground() {
	operation := "hcsshim::Process::waitBackground"
	process.logOperationBegin(operation)
	err := waitForNotification(process.callbackNumber, hcsNotificationProcessExited, nil)
	if err != nil {
		err = makeProcessError(process, "Wait", err, nil)
	}
	process.logOperationEnd(operation, err)
	process.closedWaitOnce.Do(func() {
		process.waitError = err
		close(process.waitBlock)
	})
}