We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4284b81 commit 7cd0a8bCopy full SHA for 7cd0a8b
1 file changed
ticker.go
@@ -23,7 +23,7 @@ func NewTicker() (ot *Ticker) {
23
stopCh: make(chan struct{}),
24
doneCh: make(chan struct{}),
25
}
26
- go ot.run()
+ go ot.run(ot.stopCh)
27
return
28
29
@@ -63,7 +63,7 @@ func (ot *Ticker) WaitCh() (ch <-chan struct{}) {
63
64
65
66
-func (ot *Ticker) run() {
+func (ot *Ticker) run(stopCh chan struct{}) {
67
defer func() {
68
close(ot.ch)
69
close(ot.doneCh)
@@ -75,12 +75,13 @@ func (ot *Ticker) run() {
75
for {
76
select {
77
case <-tckr.C:
78
+ newCh := make(chan struct{})
79
ot.mu.Lock()
80
oldCh := ot.ch
- ot.ch = make(chan struct{})
81
+ ot.ch = newCh
82
ot.mu.Unlock()
83
close(oldCh)
- case <-ot.stopCh:
84
+ case <-stopCh:
85
86
87
0 commit comments