diff --git a/constant.go b/constant.go index fcf4145..cc796b5 100644 --- a/constant.go +++ b/constant.go @@ -1,7 +1,7 @@ package task const ( - packageVersion = "0.9.10" + packageVersion = "0.9.11" ) const ( diff --git a/example/normal/main.go b/example/normal/main.go index 61570eb..7d0a0c5 100644 --- a/example/normal/main.go +++ b/example/normal/main.go @@ -77,8 +77,9 @@ func main() { } } - time.Sleep(time.Second * 20) + time.Sleep(time.Second * 10) + service.RemoveTask("testloop") fmt.Println(service.PrintAllTaskCounterInfo()) fmt.Println(service.GetAllTaskCountInfo()) diff --git a/tasks.go b/tasks.go index 056571a..e1bfb9f 100644 --- a/tasks.go +++ b/tasks.go @@ -270,6 +270,15 @@ func (service *TaskService) AddTask(t Task) { // RemoveTask remove task by taskid func (service *TaskService) RemoveTask(taskID string) { + //1.stop task running + t, isExists := service.GetTask(taskID) + if !isExists { + return + } + t.Stop() + service.Logger().Info(fmt.Sprint("Task:RemoveTask::StopTask => ", taskID)) + + //2.delete task from taskMap service.taskMutex.Lock() delete(service.taskMap, taskID) service.taskMutex.Unlock() @@ -338,8 +347,8 @@ func (service *TaskService) RemoveAllTask() { func (service *TaskService) StopAllTask() { service.Logger().Info("Task:StopAllTask begin...") for _, v := range service.taskMap { - service.Logger().Info(fmt.Sprint("Task:StopAllTask::StopTask => ", v.TaskID())) v.Stop() + service.Logger().Info(fmt.Sprint("Task:StopAllTask::StopTask => ", v.TaskID())) } service.Logger().Info("Task:StopAllTask end[" + string(len(service.taskMap)) + "]") } diff --git a/version.MD b/version.MD index 9e567fd..0c78d1a 100644 --- a/version.MD +++ b/version.MD @@ -1,5 +1,10 @@ ## devfeel/dottask +#### Version 0.9.11 +* bugfix: add 'StopTask' logic to RemoveTask to fix exceptions where the task cannot be GC after removal +* Thanks to @aixinaxc for #12 +* 2023-04-16 13:00 at ShangHai + #### Version 0.9.10 * feature: add LICENSE file for issue #10, thanks to @katsusan. * feature: add PackageVersion use to return packageVersion info