// DeadlineTime returns a boolean whether the drain strategy allows an infinite
// duration or otherwise the deadline time. The force drain is captured by the
// deadline time being in the past.
10117
func (d *DrainStrategy) DeadlineTime() (infinite bool, deadline time.Time) {
	// Treat the nil case as a force drain so during an upgrade where a node may
	// not have a drain strategy but has Drain set to true, it is treated as a
	// force to mimick old behavior.
	if d == nil {
		return false, time.Time{}
	}

	ns := d.Deadline.Nanoseconds()
	switch {
	case ns < 0: // Force
		return false, time.Time{}
	case ns == 0: // Infinite
		return true, time.Time{}
	default:
		return false, d.ForceDeadline
	}
}
321354
func (c *DeadlineConn) setReadTimeout() {
	if c.readTimeout != 0 {
		c.SetReadDeadline(time.Now().UTC().Add(c.readTimeout))
	}
}
929721
func TimeoutChainOption(timeout time.Duration) ChainOption {
	return func(opts *ChainOptions) {
		opts.Timeout = timeout
	}
}
1005455
func MaxTime(t, max time.Time) time.Time {
	if IsGreaterThan(t, max, false) {
		return max
	}
	return t
}
1038251
func Timeout(duration time.Duration) Option {
	return func(r *NBReader) {
		r.forceTimeout = duration
	}
}
695253
func (nd *Node) makeConnectionForPool(deadline time.Time, hint byte) {
	if deadline.IsZero() {
		deadline = time.Now().Add(_DEFAULT_TIMEOUT)
	}

	// don't even try to make a new connection if connection limit is reached
	if nd.connectionLimitReached() {
		return
	}

L:
	// don't loop forever; free the goroutine after the deadline
	if time.Now().After(deadline) {
		return
	}

	conn, err := nd.newConnection(false)
	if err != nil {
		// The following check can help break the loop under heavy load and remove
		// quite a lot of latency.
		if err == ErrTooManyConnectionsForNode {
			// The connection pool is already full. No need for more connections.
			return
		}

		Logger.Error("Error trying to making a connection to the node %s: %s", nd.String(), err.Error())

		time.Sleep(time.Millisecond)
		goto L
	}

	nd.putConnectionWithHint(conn, hint)
}
376127
func (cs cursorStats) ExecutionTime() time.Duration {
	return time.Duration(cs.ExecutionTimeInt) * time.Second
}
875342
func Time(from time.Time, maxDelta time.Duration) time.Time {
	globalLk.Lock()
	defer globalLk.Unlock()
	return globalGen.Time(from, maxDelta)
}
525181
func (s *StreamEncoder) Deadline() (time.Time, bool) {
	if s.deadline != nil {
		return *s.deadline, true
	}
	return time.Time{}, false
}
802590
func TimeRange(after, before time.Time) QueryOpt {
	return QueryOpt{func(o *QueryOptions) {
		o.AfterDate = after
		o.BeforeDate = before
	}}
}
44879
func MonotonicRetryStrategyFunc(seconds int) RetryStrategyFunc {
	return func(iteration int64) time.Duration {
		return time.Duration(seconds) * time.Second
	}
}
995563
func (s *Simulator) AdvanceTime(d time.Duration) {
	switch {
	case d == 0:
		return
	case d < 0:
		panic("time must move forward only")
	}

	// First tick ever? Reset Now to Epoch, since Epoch is our beginning of times.
	if s.Now.IsZero() {
		s.Now = s.Epoch
	}

	deadline := s.Now.Add(d)
	for {
		// Nothing is happening at all or events happen later than we wish to go?
		if ev := s.peekEvent(); ev == nil || ev.eta.After(deadline) {
			s.Now = deadline
			return
		}

		// Advance the time to the point when the event is happening and execute the
		// event's callback. It may result in most stuff added to the timeline which
		// we will discover on the next iteration of the loop.
		ev := s.popEvent()
		s.Now = ev.eta
		ev.cb()
	}
}
972649
func (t *StandardResettingTimer) Time(f func()) {
	ts := time.Now()
	f()
	t.Update(time.Since(ts))
}
513838
func (b *backoff) Duration() (dur time.Duration) {
	// Zero-values are nonsensical, so we use
	// them to apply defaults
	if b.Max == 0 {
		b.Max = 10 * time.Second
	}

	if b.Initial == 0 {
		b.Initial = 100 * time.Millisecond
	}

	// calculate this duration
	if dur = time.Duration(1 << uint(b.attempts)); dur > 0 {
		dur = dur * b.Initial
	} else {
		dur = b.Max
	}

	if b.Jitter > 0 {
		dur = dur + time.Duration(rand.Intn(int(b.Jitter)))
	}

	// bump attempts count
	b.attempts++

	return dur
}
1168790
func (h *Timing) ContentLoadTime(contentLoadTime int64) *Timing {
	h.contentLoadTime = contentLoadTime
	h.contentLoadTimeSet = true
	return h
}
62210
func Delay(duration time.Duration) Strategy {
	return func(attempt uint) bool {
		if 0 == attempt {
			time.Sleep(duration)
		}

		return true
	}
}
587037
func WaitTime(value time.Duration) Option {
	return func(o *Options) {
		o.waitTime = value
	}
}