fix: send on closed channel
This commit is contained in:
@ -30,6 +30,10 @@ func (c *Cron) Do(f func()) {
|
||||
}
|
||||
|
||||
func (c *Cron) Stop() {
|
||||
c.ch <- struct{}{}
|
||||
close(c.ch)
|
||||
select {
|
||||
case _, _ = <-c.ch:
|
||||
default:
|
||||
c.ch <- struct{}{}
|
||||
close(c.ch)
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ func TestCron(t *testing.T) {
|
||||
c.Do(func() {
|
||||
t.Logf("cron log")
|
||||
})
|
||||
time.Sleep(time.Second * 5)
|
||||
time.Sleep(time.Second * 3)
|
||||
c.Stop()
|
||||
c.Stop()
|
||||
}
|
||||
|
Reference in New Issue
Block a user