2022-11-24 22:53:58 +01:00
|
|
|
const SocketAuthority = require('../SocketAuthority')
|
2022-10-02 21:16:17 +02:00
|
|
|
|
2022-11-24 22:53:58 +01:00
|
|
|
class TaskManager {
|
|
|
|
constructor() {
|
2022-10-02 21:16:17 +02:00
|
|
|
this.tasks = []
|
|
|
|
}
|
|
|
|
|
|
|
|
addTask(task) {
|
|
|
|
this.tasks.push(task)
|
2022-11-24 22:53:58 +01:00
|
|
|
SocketAuthority.emitter('task_started', task.toJSON())
|
2022-10-02 21:16:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
taskFinished(task) {
|
|
|
|
if (this.tasks.some(t => t.id === task.id)) {
|
2022-10-02 21:31:04 +02:00
|
|
|
this.tasks = this.tasks.filter(t => t.id !== task.id)
|
2022-11-24 22:53:58 +01:00
|
|
|
SocketAuthority.emitter('task_finished', task.toJSON())
|
2022-10-02 21:16:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = TaskManager
|