|
@ -20,15 +20,17 @@ type Ticker interface { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
//----------------------------------------
|
|
|
// defaultTickerMaker
|
|
|
|
|
|
|
|
|
// defaultTicker
|
|
|
|
|
|
|
|
|
|
|
|
var _ Ticker = (*defaultTicker)(nil) |
|
|
|
|
|
|
|
|
|
|
|
type defaultTicker time.Ticker |
|
|
|
|
|
|
|
|
func defaultTickerMaker(dur time.Duration) Ticker { |
|
|
func defaultTickerMaker(dur time.Duration) Ticker { |
|
|
ticker := time.NewTicker(dur) |
|
|
ticker := time.NewTicker(dur) |
|
|
return (*defaultTicker)(ticker) |
|
|
return (*defaultTicker)(ticker) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type defaultTicker time.Ticker |
|
|
|
|
|
|
|
|
|
|
|
// Implements Ticker
|
|
|
// Implements Ticker
|
|
|
func (t *defaultTicker) Chan() <-chan time.Time { |
|
|
func (t *defaultTicker) Chan() <-chan time.Time { |
|
|
return t.C |
|
|
return t.C |
|
@ -151,12 +153,13 @@ func NewRepeatTimerWithTickerMaker(name string, dur time.Duration, tm TickerMake |
|
|
return t |
|
|
return t |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// receive ticks on ch, send out on t.ch
|
|
|
func (t *RepeatTimer) fireRoutine(ch <-chan time.Time, quit <-chan struct{}) { |
|
|
func (t *RepeatTimer) fireRoutine(ch <-chan time.Time, quit <-chan struct{}) { |
|
|
for { |
|
|
for { |
|
|
select { |
|
|
select { |
|
|
case t_ := <-ch: |
|
|
|
|
|
|
|
|
case tick := <-ch: |
|
|
select { |
|
|
select { |
|
|
case t.ch <- t_: |
|
|
|
|
|
|
|
|
case t.ch <- tick: |
|
|
case <-quit: |
|
|
case <-quit: |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|