فهرست منبع

check closed again before scheduling another task

Darien Raymond 7 سال پیش
والد
کامیت
596d05bff5
1فایلهای تغییر یافته به همراه6 افزوده شده و 1 حذف شده
  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
 }