// Returns a time.Timer that calls f. The timer is initially stopped.
433753
func StoppedFuncTimer(f func()) (t *time.Timer) {
	t = time.AfterFunc(math.MaxInt64, f)
	if !t.Stop() {
		panic("timer already fired")
	}
	return
}
462655
func (t *Timer) Stop() bool {
	if t.timer != nil {
		return t.timer.Stop()
	}

	registered := !t.stopped
	t.mock.removeClockTimer((*internalTimer)(t))
	t.stopped = true
	return registered
}
8057
func DurationFunc(v string) (interface{}, error) {
	s, err := time.ParseDuration(v)
	if err != nil {
		return nil, fmt.Errorf("unable to parser duration: %v", err)
	}
	return s, err
}
368799
func (t *FixedInterval) Start() bool {
	t.Lock()
	defer t.Unlock()

	// If the timer is already started or uninitialized return false.
	if t.running() || !t.initialized {
		return false
	}

	// Create the new timer with the delay
	t.timer = time.AfterFunc(t.GetDelay(), t.action)
	return true
}
731149
func AfterFunc(d time.Duration, f func()) Timer {
	return provider.AfterFunc(d, f)
}
186975
func TimeRange(from, to time.Time) func(Call) error {
	return TimeRangeUint64(uint64(from.UnixNano()/1e6), uint64(to.UnixNano()/1e6))
}
80063
func (c *Command) ExecTimeout(timeout time.Duration, f interface{}, args ...interface{}) Return {
	var retvals chan []reflect.Value = make(chan []reflect.Value)
	val := reflect.ValueOf(f)
	if val.Kind() != reflect.Func {
		panic("f is not a function")
	}
	t := val.Type()
	if t.NumIn() != len(args) {
		panic("invalid number of arguments")
	}
	a := make([]reflect.Value, len(args))
	for i, arg := range args {
		a[i] = reflect.ValueOf(arg)
		if !a[i].Type().AssignableTo(t.In(i)) {
			panic(fmt.Sprintf("invalid argument type, argument %v must be assignable to %v", a[i].Type(), t.In(i)))
		}
	}
	go func() {
		var err error
		if timeout != 0 {
			err = c.Conn.SetDeadline(time.Now().Add(timeout))
			if err != nil {
				log.Println("SetDeadline failed with error:", e.Trace(e.Forward(err)))
			}
		} else {
			err = c.Conn.SetDeadline(time.Time{})
			if err != nil {
				log.Println("SetDeadline failed with error:", e.Trace(e.Forward(err)))
			}
		}
		values := val.Call(a)
		if timeout != 0 {
			err = c.Conn.SetDeadline(time.Time{})
			if err != nil {
				log.Println("SetDeadline failed with error:", e.Trace(e.Forward(err)))
			}
		}
		setError(values, err)
		retvals <- values
	}()

	return func(args ...interface{}) {
		retvals := <-retvals
		if len(retvals) != len(args) {
			panic(fmt.Sprintf("the number of arguments (%v) in Returns must be equal to the number of return values in the function (%v)", len(args), len(retvals)))
		}
		for i, retval := range retvals {
			val := reflect.ValueOf(args[i])
			if val.Kind() != reflect.Ptr {
				panic("Returns arguments must be pointers")
			}
			if retval.Type() != val.Elem().Type() {
				panic("diferent kind")
			}
			val.Elem().Set(retval)
		}
	}
}
1236960
func NewTimeLimiter(window, limit time.Duration, now time.Time) *TimeLimiter {
	l := TimeLimiter{
		since:  now,
		next:   now.Add(window),
		window: window,
		limit:  limit,
		factor: float64(window) / float64(limit),
	}
	return &l
}
195382
func (fc *FakeClock) AfterFunc(d time.Duration, f func()) Timer {
	return fc.FakeAfterFunc(d, f)
}
888939
func (mr *MockScopeMockRecorder) Timer(name interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Timer", reflect.TypeOf((*MockScope)(nil).Timer), name)
}
721038
func GetOrRegisterTimer(name string, r Registry) Timer {
	if nil == r {
		r = DefaultRegistry
	}
	return r.GetOrRegister(name, NewTimer).(Timer)
}
888079
func (fc *FakeClock) Timer(d time.Duration) Timer {
	return fc.FakeTimer(d)
}
529453
func NewTimer() *Timer {
	return &Timer{t: time.NewTimer(time.Duration(math.MaxInt64))}
}
133136
func (e *Event) TimeDiff(key string, t time.Time, start time.Time) *Event {
	if e == nil {
		return e
	}
	var d time.Duration
	if t.After(start) {
		d = t.Sub(start)
	}
	e.buf = enc.AppendDuration(enc.AppendKey(e.buf, key), d, DurationFieldUnit, DurationFieldInteger)
	return e
}
1145978
func (h *haManager) timer() <-chan time.Time {
	if s := h.state(); s == seesaw.HADisabled || s == seesaw.HAUnknown {
		return make(chan time.Time)
	}
	// TODO(angusc): Make this clock-jump safe.
	h.statusLock.RLock()
	deadline := h.status.LastUpdate.Add(h.timeout)
	h.statusLock.RUnlock()
	return time.After(deadline.Sub(time.Now()))
}
891204
func (t *PCPTimer) Stop() (float64, error) {
	t.mutex.Lock()
	defer t.mutex.Unlock()

	if !t.started {
		return 0, errors.New("trying to stop a stopped timer")
	}

	d := time.Since(t.since)

	var inc float64
	switch t.pcpMetricDesc.Unit() {
	case NanosecondUnit:
		inc = float64(d.Nanoseconds())
	case MicrosecondUnit:
		inc = float64(d.Nanoseconds()) * 1e-3
	case MillisecondUnit:
		inc = float64(d.Nanoseconds()) * 1e-6
	case SecondUnit:
		inc = d.Seconds()
	case MinuteUnit:
		inc = d.Minutes()
	case HourUnit:
		inc = d.Hours()
	}

	v := t.val.(float64)

	err := t.set(v + inc)
	if err != nil {
		return -1, err
	}

	t.started = false
	return v + inc, nil
}
89950
func StartTime(t time.Time) func(*sonyflake.Settings) {
	return func(s *sonyflake.Settings) {
		s.StartTime = t
	}
}