// Sleep sleeps for the duration
974330
func (agent *ActionAgent) Sleep(ctx context.Context, duration time.Duration) {
	if err := agent.lock(ctx); err != nil {
		// client gave up
		return
	}
	defer agent.unlock()

	time.Sleep(duration)
}
1023146
func (t *SleepClock) Advance(d time.Duration) {
	t.mu.Lock()
	defer t.mu.Unlock()
	t.currentTime = t.currentTime.Add(d)
	for k, v := range t.waiters {
		if k.Before(t.currentTime) {
			for _, c := range v {
				c <- t.currentTime
			}
			delete(t.waiters, k)
		}
	}

}
1039063
func InterruptableSleep(ctx context.Context, d time.Duration) error {
	timer := time.NewTimer(d)

	select {
	case <-timer.C:
		return nil
	case <-ctx.Done():
		return errors.New("sleep interrupted by context")
	}
}
1168782
func (c *client) trysleep(d time.Duration) {
	select {
	case <-time.After(d):
	case <-c.stop:
	}
}
494851
func Sleep(d time.Duration) {
	if isTimeFrozen && d > 0 {
		currentFrozenTime = currentFrozenTime.Add(d)

		return
	}

	time.Sleep(d)
}
378049
func (s *Server) Listen(ttl time.Duration) {
	listener := make(chan *docker.APIEvents)
	// TODO: figure out why we need to sleep for 10 milliseconds
	// https://github.com/fsouza/go-dockerclient/blob/0236a64c6c4bd563ec277ba00e370cc753e1677c/event_test.go#L43
	defer func() { time.Sleep(10 * time.Millisecond); s.DockerClient.RemoveEventListener(listener) }()
	if err := s.DockerClient.AddEventListener(listener); err != nil {
		log.Fatal(err)
	}
	for {
		select {
		case event := <-listener:
			if event.Status == "start" {
				container, err := s.getContainer(event.ID)
				if err != nil {
					log.Println(err)
					continue
				}
				s.publishContainer(container, ttl)
			} else if event.Status == "stop" {
				s.removeContainer(event.ID)
			}
		}
	}
}
1099286
func (t *limiter) Take() time.Time {
	t.Lock()
	defer t.Unlock()

	now := t.clock.Now()

	// If this is our first request, then we allow it.
	if t.last.IsZero() {
		t.last = now
		return t.last
	}

	// sleepFor calculates how much time we should sleep based on
	// the perRequest budget and how long the last request took.
	// Since the request may take longer than the budget, this number
	// can get negative, and is summed across requests.
	t.sleepFor += t.perRequest - now.Sub(t.last)

	// We shouldn't allow sleepFor to get too negative, since it would mean that
	// a service that slowed down a lot for a short period of time would get
	// a much higher RPS following that.
	if t.sleepFor < t.maxSlack {
		t.sleepFor = t.maxSlack
	}

	// If sleepFor is positive, then we should sleep now.
	if t.sleepFor > 0 {
		t.clock.Sleep(t.sleepFor)
		t.last = now.Add(t.sleepFor)
		t.sleepFor = 0
	} else {
		t.last = now
	}

	return t.last
}
779091
func (ttles *TTLExpirationScheduler) Stop() {
	ttles.Lock()
	defer ttles.Unlock()

	if err := ttles.writeState(); err != nil {
		dcontext.GetLogger(ttles.ctx).Errorf("Error writing scheduler state: %s", err)
	}

	for _, entry := range ttles.entries {
		entry.timer.Stop()
	}

	close(ttles.doneChan)
	ttles.saveTimer.Stop()
	ttles.stopped = true
}
842521
func SleepContext(ctx context.Context, duration time.Duration) error {
	if duration == 0 {
		return nil
	}

	t := time.NewTimer(duration)
	select {
	case <-t.C:
		return nil
	case <-ctx.Done():
		t.Stop()
		return ctx.Err()
	}
}
833756
func sleepRand() time.Duration {
	randSec := maxOnlineDuration.Seconds() - minOnlineDuration.Seconds()
	sleepSec := rand.Intn(int(randSec)) + int(minOnlineDuration.Seconds())
	time.Sleep(time.Duration(sleepSec) * time.Second)
	return time.Duration(sleepSec) * time.Second
}
701744
func randSleep(n, m int) {
	r := m
	if m-n > 0 {
		r = rand.Intn(m-n) + n
	}
	time.Sleep(time.Duration(r) * time.Second)
}
738131
func Delay(duration int) {
	time.Sleep(time.Duration(duration) * time.Millisecond)
}
754470
func (b *Exponential) Wait(ctx context.Context) error {
	b.attempt++
	t := b.Duration(b.attempt)

	log.WithFields(logrus.Fields{
		"time":    t,
		"attempt": b.attempt,
		"name":    b.Name,
	}).Debug("Sleeping with exponential backoff")

	select {
	case <-ctx.Done():
		return fmt.Errorf("exponential backoff cancelled via context: %s", ctx.Err())
	case <-time.After(t):
	}

	return nil
}
107521
func RandomDuration(max time.Duration) time.Duration {
	if max == 0 {
		return 0
	}

	var sleepns int64
	maxSleep := big.NewInt(max.Nanoseconds())
	if j, err := rand.Int(rand.Reader, maxSleep); err == nil {
		sleepns = j.Int64()
	}

	return time.Duration(sleepns)
}
549336
func Sleep(tm int) {
	time.Sleep(time.Duration(tm) * time.Second)
}
268610
func PgSleepUntil(db XODB, v0 time.Time) error {
	var err error

	// sql query
	const sqlstr = `SELECT pg_catalog.pg_sleep_until($1)`

	// run query
	XOLog(sqlstr)
	_, err = db.Exec(sqlstr)
	return err
}
202234
func (g *GY520) Wake() error {
	v, e := g.device.ReadByte(REG_PWR_MGMT_1)
	if e != nil {
		return e
	}

	v &= ^byte(PARAM_SLEEP)

	e = g.device.WriteByte(REG_PWR_MGMT_1, v)
	if e != nil {
		return e
	}

	return nil
}