Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
wongoo committed Jun 25, 2019
1 parent 971212c commit a06ff79
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
7 changes: 1 addition & 6 deletions time/wheel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -62,7 +59,6 @@ func NewWheel(span time.Duration, buckets int) *Wheel {
close(notify)
}
}
// fmt.Println("timer costs:", cw.Count()/1e9, "s")
}()

return w
Expand All @@ -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()

Expand Down
24 changes: 10 additions & 14 deletions time/wheel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand All @@ -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
}
}
}
Expand Down

0 comments on commit a06ff79

Please sign in to comment.