优化代码

This commit is contained in:
GoEdgeLab
2021-12-08 22:19:15 +08:00
parent c96406ff64
commit 6be26c0ffb
4 changed files with 34 additions and 24 deletions

View File

@@ -41,9 +41,9 @@ func TestTicker2(t *testing.T) {
for {
t.Log("loop")
select {
case <-ticker.C:
case <-ticker.raw.C:
t.Log("tick")
case <-ticker.S:
case <-ticker.done:
return
}
}
@@ -63,3 +63,17 @@ func TestTickerEvery(t *testing.T) {
})
wg.Wait()
}
func TestTicker_StopTwice(t *testing.T) {
ticker := NewTicker(3 * time.Second)
go func() {
time.Sleep(10 * time.Second)
ticker.Stop()
ticker.Stop()
}()
for ticker.Next() {
t.Log("tick")
}
t.Log("finished")
}