Fix:修复批量执行类添加同名任务时任务未更新为最小任务的问题

This commit is contained in:
wanglin2
2023-11-28 17:36:13 +08:00
parent 51dcb1f54f
commit a0f56473ee

View File

@@ -12,6 +12,7 @@ class BatchExecution {
// 添加任务
push(name, fn) {
if (this.has[name]) {
this.replaceTask(name, fn)
return
}
this.has[name] = true
@@ -22,6 +23,19 @@ class BatchExecution {
this.nextTick()
}
// 替换任务
replaceTask(name, fn) {
const index = this.queue.findIndex(item => {
return item.name === name
})
if (index !== -1) {
this.queue[index] = {
name,
fn
}
}
}
// 执行队列
flush() {
let fns = this.queue.slice(0)