1
0
mirror of https://github.com/siddontang/go.git synced 2025-04-24 13:48:52 +08:00

timingwheel: fix time-skew error

This commit is contained in:
siddontang 2016-10-05 19:08:31 +08:00
parent a30862d58d
commit 1e9ce2a5ac

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]