timingwheel: fix time-skew error

This commit is contained in:
siddontang 2016-10-05 19:08:31 +08:00
parent a30862d58d
commit 1e9ce2a5ac
1 changed files with 6 additions and 1 deletions

View File

@ -51,9 +51,14 @@ func (w *TimingWheel) After(timeout time.Duration) <-chan struct{} {
panic("timeout too much, over maxtimeout")
}
index := int(timeout / w.interval)
if 0 < index {
index--
}
w.Lock()
index := (w.pos + int(timeout/w.interval)) % len(w.cs)
index = (w.pos + index) % len(w.cs)
b := w.cs[index]