Commit a06ff797 authored by wongoo's avatar wongoo

remove unused code

parent 971212c5
...@@ -39,19 +39,16 @@ func NewWheel(span time.Duration, buckets int) *Wheel { ...@@ -39,19 +39,16 @@ func NewWheel(span time.Duration, buckets int) *Wheel {
period: span * (time.Duration(buckets)), period: span * (time.Duration(buckets)),
ticker: time.NewTicker(span), ticker: time.NewTicker(span),
index: 0, index: 0,
ring: make([](chan struct{}), buckets), ring: make([]chan struct{}, buckets),
now: time.Now(), now: time.Now(),
} }
go func() { go func() {
var notify chan struct{} var notify chan struct{}
// var cw CountWatch
// cw.Start()
for t := range w.ticker.C { for t := range w.ticker.C {
w.Lock() w.Lock()
w.now = t w.now = t
// fmt.Println("index:", w.index, ", value:", w.bitmap.Get(w.index))
notify = w.ring[w.index] notify = w.ring[w.index]
w.ring[w.index] = nil w.ring[w.index] = nil
w.index = (w.index + 1) % len(w.ring) w.index = (w.index + 1) % len(w.ring)
...@@ -62,7 +59,6 @@ func NewWheel(span time.Duration, buckets int) *Wheel { ...@@ -62,7 +59,6 @@ func NewWheel(span time.Duration, buckets int) *Wheel {
close(notify) close(notify)
} }
} }
// fmt.Println("timer costs:", cw.Count()/1e9, "s")
}() }()
return w return w
...@@ -87,7 +83,6 @@ func (w *Wheel) After(timeout time.Duration) <-chan struct{} { ...@@ -87,7 +83,6 @@ func (w *Wheel) After(timeout time.Duration) <-chan struct{} {
if w.ring[pos] == nil { if w.ring[pos] == nil {
w.ring[pos] = make(chan struct{}) w.ring[pos] = make(chan struct{})
} }
// fmt.Println("pos:", pos)
c := w.ring[pos] c := w.ring[pos]
w.Unlock() w.Unlock()
......
...@@ -24,13 +24,11 @@ func TestWheel(t *testing.T) { ...@@ -24,13 +24,11 @@ func TestWheel(t *testing.T) {
cw.Start() cw.Start()
for { for {
select { <-wheel.After(TimeMillisecondDuration(1000))
case <-wheel.After(TimeMillisecondDuration(1000)): fmt.Println("loop:", index)
fmt.Println("loop:", index) index++
index++ if index >= 150 {
if index >= 150 { return
return
}
} }
} }
} }
...@@ -54,13 +52,11 @@ func TestWheels(t *testing.T) { ...@@ -54,13 +52,11 @@ func TestWheels(t *testing.T) {
defer wg.Done() defer wg.Done()
var index int var index int
for { for {
select { <-wheel.After(d)
case <-wheel.After(d): fmt.Println("loop:", index, ", interval:", d)
fmt.Println("loop:", index, ", interval:", d) index++
index++ if index >= 100 {
if index >= 100 { return
return
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment