mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
♻️ 重构定时任务实现 Fix https://github.com/siyuan-note/siyuan/issues/7171
This commit is contained in:
parent
b601a9af7c
commit
89ed7f2ad9
4 changed files with 30 additions and 51 deletions
|
@ -47,7 +47,6 @@ func PrependTask(action string, handler interface{}, args ...interface{}) {
|
|||
return
|
||||
}
|
||||
|
||||
cancelTask(action, args...)
|
||||
taskQueue = append([]*Task{newTask(action, handler, args...)}, taskQueue...)
|
||||
}
|
||||
|
||||
|
@ -60,30 +59,9 @@ func AppendTask(action string, handler interface{}, args ...interface{}) {
|
|||
return
|
||||
}
|
||||
|
||||
cancelTask(action, args...)
|
||||
taskQueue = append(taskQueue, newTask(action, handler, args...))
|
||||
}
|
||||
|
||||
func cancelTask(action string, args ...interface{}) {
|
||||
for i := len(taskQueue) - 1; i >= 0; i-- {
|
||||
task := taskQueue[i]
|
||||
if action == task.Action {
|
||||
if len(task.Args) != len(args) {
|
||||
continue
|
||||
}
|
||||
|
||||
for j, arg := range args {
|
||||
if arg != task.Args[j] {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
taskQueue = append(taskQueue[:i], taskQueue[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func newTask(action string, handler interface{}, args ...interface{}) *Task {
|
||||
return &Task{
|
||||
Action: action,
|
||||
|
@ -181,7 +159,7 @@ func execTask(task *Task) {
|
|||
}
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*12)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*7)
|
||||
defer cancel()
|
||||
ch := make(chan bool, 1)
|
||||
go func() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue