This commit is contained in:
SrGooglo 2025-05-15 13:04:09 +00:00
parent 2731fd7b4e
commit 79b8ecc98f

View File

@ -21,7 +21,9 @@ export default class TasksQueue extends Core {
processTasks() {
if (this.runningTasksIds.length >= TasksQueue.maxRunningTasks ?? 1) {
this.console.log("We are already running the maximum number of tasks")
this.console.log(
"We are already running the maximum number of tasks",
)
return false
}
@ -47,17 +49,20 @@ export default class TasksQueue extends Core {
// add the task to the running tasks array
this.runningTasksIds.push(task.id)
const taskResult = await task.fn()
.catch((error) => {
const taskResult = await task.fn().catch((error) => {
// delete the task from the running tasks array
this.runningTasksIds = this.runningTasksIds.filter((runningTaskId) => runningTaskId !== task.id)
this.runningTasksIds = this.runningTasksIds.filter(
(runningTaskId) => runningTaskId !== task.id,
)
// propagate the error through an exception
throw error
})
// delete the task from the running tasks array
this.runningTasksIds = this.runningTasksIds.filter((runningTaskId) => runningTaskId !== task.id)
this.runningTasksIds = this.runningTasksIds.filter(
(runningTaskId) => runningTaskId !== task.id,
)
return taskResult
})