diff --git a/toolbox/task.go b/toolbox/task.go index 537de428..abd411c8 100644 --- a/toolbox/task.go +++ b/toolbox/task.go @@ -389,6 +389,10 @@ func dayMatches(s *Schedule, t time.Time) bool { // StartTask start all tasks func StartTask() { + if isstart { + //If already started, no need to start another goroutine. + return + } isstart = true go run() } @@ -432,8 +436,11 @@ func run() { // StopTask stop all tasks func StopTask() { - isstart = false - stop <- true + if isstart { + isstart = false + stop <- true + } + } // AddTask add task with name