diff --git a/time/wheel.go b/time/wheel.go index 6078392..dcdf7c8 100644 --- a/time/wheel.go +++ b/time/wheel.go @@ -39,19 +39,16 @@ func NewWheel(span time.Duration, buckets int) *Wheel { period: span * (time.Duration(buckets)), ticker: time.NewTicker(span), index: 0, - ring: make([](chan struct{}), buckets), + ring: make([]chan struct{}, buckets), now: time.Now(), } go func() { var notify chan struct{} - // var cw CountWatch - // cw.Start() for t := range w.ticker.C { w.Lock() w.now = t - // fmt.Println("index:", w.index, ", value:", w.bitmap.Get(w.index)) notify = w.ring[w.index] w.ring[w.index] = nil w.index = (w.index + 1) % len(w.ring) @@ -62,7 +59,6 @@ func NewWheel(span time.Duration, buckets int) *Wheel { close(notify) } } - // fmt.Println("timer costs:", cw.Count()/1e9, "s") }() return w @@ -87,7 +83,6 @@ func (w *Wheel) After(timeout time.Duration) <-chan struct{} { if w.ring[pos] == nil { w.ring[pos] = make(chan struct{}) } - // fmt.Println("pos:", pos) c := w.ring[pos] w.Unlock() diff --git a/time/wheel_test.go b/time/wheel_test.go index e58c011..3b1d3bd 100644 --- a/time/wheel_test.go +++ b/time/wheel_test.go @@ -24,13 +24,11 @@ func TestWheel(t *testing.T) { cw.Start() for { - select { - case <-wheel.After(TimeMillisecondDuration(1000)): - fmt.Println("loop:", index) - index++ - if index >= 150 { - return - } + <-wheel.After(TimeMillisecondDuration(1000)) + fmt.Println("loop:", index) + index++ + if index >= 150 { + return } } } @@ -54,13 +52,11 @@ func TestWheels(t *testing.T) { defer wg.Done() var index int for { - select { - case <-wheel.After(d): - fmt.Println("loop:", index, ", interval:", d) - index++ - if index >= 100 { - return - } + <-wheel.After(d) + fmt.Println("loop:", index, ", interval:", d) + index++ + if index >= 100 { + return } } }