Browse Source

check closed again before scheduling another task

Darien Raymond 7 năm trước cách đây
mục cha
commit
596d05bff5
1 tập tin đã thay đổi với 6 bổ sung1 xóa
  1. 6 1
      common/task/periodic.go

+ 6 - 1
common/task/periodic.go

@@ -42,12 +42,17 @@ func (t *Periodic) checkedExecute() error {
 	}
 
 	t.access.Lock()
+	defer t.access.Unlock()
+
+	if t.closed {
+		return nil
+	}
+
 	t.timer = time.AfterFunc(t.Interval, func() {
 		if err := t.checkedExecute(); err != nil && t.OnError != nil {
 			t.OnError(err)
 		}
 	})
-	t.access.Unlock()
 
 	return nil
 }