Fix ThrottleTimer null-pointer error / race condition

This commit is contained in:
Jae Kwon 2016-12-06 01:39:04 -08:00
parent 6b4160f2a5
commit 70e694ee76
1 changed files with 2 additions and 0 deletions

View File

@ -26,7 +26,9 @@ func NewThrottleTimer(name string, dur time.Duration) *ThrottleTimer {
var ch = make(chan struct{})
var quit = make(chan struct{})
var t = &ThrottleTimer{Name: name, Ch: ch, dur: dur, quit: quit}
t.mtx.Lock()
t.timer = time.AfterFunc(dur, t.fireRoutine)
t.mtx.Unlock()
t.timer.Stop()
return t
}