This commit is contained in:
Liang Ding 2023-01-27 12:27:27 +08:00
parent b601a9af7c
commit 89ed7f2ad9
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
4 changed files with 30 additions and 51 deletions

View file

@ -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() {