风扇滑翔翼
2026-11-25 14:37:40 +00:00
committed by GitHub
co-authored by StarProxima
parent 862e59a2f2
commit b56ffef338
5 changed files with 37 additions and 37 deletions
+3 -7
View File
@@ -58,15 +58,11 @@ func (t *Periodic) Start() error {
return nil
}
t.running = true
t.timer = time.AfterFunc(t.Interval, func() {
t.checkedExecute()
})
t.access.Unlock()
if err := t.checkedExecute(); err != nil {
t.access.Lock()
t.running = false
t.access.Unlock()
return err
}
return nil
}
+6 -6
View File
@@ -20,17 +20,17 @@ func TestPeriodicTaskStop(t *testing.T) {
common.Must(task.Start())
time.Sleep(time.Second * 5)
common.Must(task.Close())
if value != 3 {
t.Fatal("expected 3, but got ", value)
if value != 2 {
t.Fatal("expected 2, but got ", value)
}
time.Sleep(time.Second * 4)
if value != 3 {
t.Fatal("expected 3, but got ", value)
if value != 2 {
t.Fatal("expected 2, but got ", value)
}
common.Must(task.Start())
time.Sleep(time.Second * 3)
if value != 5 {
t.Fatal("Expected 5, but ", value)
if value != 3 {
t.Fatal("Expected 3, but ", value)
}
common.Must(task.Close())
}