mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
🎨 改进内核任务调度机制提升稳定性 https://github.com/siyuan-note/siyuan/issues/7113
This commit is contained in:
parent
3f87f3da5e
commit
9b28cdfdf1
3 changed files with 29 additions and 19 deletions
|
@ -52,6 +52,7 @@ func PrependTask(action string, handler interface{}, args ...interface{}) {
|
|||
return
|
||||
}
|
||||
|
||||
cancelTask(action, args...)
|
||||
taskQueue = append([]*Task{newTask(action, handler, args...)}, taskQueue...)
|
||||
}
|
||||
|
||||
|
@ -64,20 +65,26 @@ func AppendTask(action string, handler interface{}, args ...interface{}) {
|
|||
return
|
||||
}
|
||||
|
||||
cancelTask(action, args...)
|
||||
taskQueue = append(taskQueue, newTask(action, handler, args...))
|
||||
}
|
||||
|
||||
func CancelTask(actions ...string) {
|
||||
queueLock.Lock()
|
||||
defer queueLock.Unlock()
|
||||
|
||||
func cancelTask(action string, args ...interface{}) {
|
||||
for i := len(taskQueue) - 1; i >= 0; i-- {
|
||||
task := taskQueue[i]
|
||||
for _, action := range actions {
|
||||
if action == task.Action {
|
||||
taskQueue = append(taskQueue[:i], taskQueue[i+1:]...)
|
||||
break
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue