9 ThrottleTimer fires an event at most "dur" after each .Set() call.
10 If a short burst of .Set() calls happens, ThrottleTimer fires once.
11 If a long continuous burst of .Set() calls happens, ThrottleTimer fires
12 at most once every "dur".
14 type ThrottleTimer struct {
25 func NewThrottleTimer(name string, dur time.Duration) *ThrottleTimer {
26 var ch = make(chan struct{})
27 var quit = make(chan struct{})
28 var t = &ThrottleTimer{Name: name, Ch: ch, dur: dur, quit: quit}
30 t.timer = time.AfterFunc(dur, t.fireRoutine)
36 func (t *ThrottleTimer) fireRoutine() {
40 case t.Ch <- struct{}{}:
49 func (t *ThrottleTimer) Set() {
58 func (t *ThrottleTimer) Unset() {
65 // For ease of .Stop()'ing services before .Start()'ing them,
66 // we ignore .Stop()'s on nil ThrottleTimers
67 func (t *ThrottleTimer) Stop() bool {