添加任务队列
This commit is contained in:
28
src/component/Canvas/utils/TaskQueue.js
Normal file
28
src/component/Canvas/utils/TaskQueue.js
Normal file
@@ -0,0 +1,28 @@
|
||||
export default class TaskQueue {
|
||||
constructor() {
|
||||
this.tasks = [];
|
||||
this.running = false;
|
||||
}
|
||||
// 添加任务
|
||||
addTask(task) {
|
||||
this.tasks.push(task);
|
||||
// 执行任务
|
||||
this.executeTasks();
|
||||
}
|
||||
// 执行任务
|
||||
async executeTasks() {
|
||||
if (this.running) {
|
||||
return;
|
||||
}
|
||||
this.running = true;
|
||||
for (const task of this.tasks) {
|
||||
await task();
|
||||
}
|
||||
this.running = false;
|
||||
this.clearTasks();
|
||||
}
|
||||
// 清空任务队列
|
||||
clearTasks() {
|
||||
this.tasks = [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user