@coya/task-manager
Advanced tools
Comparing version
@@ -136,9 +136,7 @@ "use strict"; | ||
this.logs.info('Task "' + task.name + '" stopped and removed from the tasks list.'); | ||
if (this._tasks.length == 0) | ||
if (!this._tasks.length) | ||
this.endTaskManager(); | ||
} | ||
else if (result && result.stopAll) { | ||
this.cancelAllTasks(); | ||
else if (result && result.stopAll) | ||
this.endTaskManager(); | ||
} | ||
else | ||
@@ -152,9 +150,7 @@ this.scheduleTask(task); | ||
this.logs.error('Task "' + task.name + '" stopped and removed from the tasks list.'); | ||
if (this._tasks.length == 0) | ||
this.endTaskManager(); | ||
if (!this._tasks.length) | ||
this.endTaskManager(true); | ||
} | ||
else if (error && error.stopAll) { | ||
this.cancelAllTasks(true); | ||
this.endTaskManager(); | ||
} | ||
else if (error && error.stopAll) | ||
this.endTaskManager(true); | ||
else | ||
@@ -170,5 +166,12 @@ this.scheduleTask(task); | ||
} | ||
endTaskManager() { | ||
endTaskManager(isError) { | ||
if (!this._isEnded) { | ||
this._isEnded = true; | ||
if (this._tasks.length) { | ||
this._tasks.forEach((task) => { | ||
task.cancel(); | ||
}); | ||
this._tasks = []; | ||
(isError ? this.logs.error : this.logs.info).call(this, 'All tasks have been cancelled and removed from the tasks list.'); | ||
} | ||
if (this._end) | ||
@@ -178,10 +181,3 @@ this._end(); | ||
} | ||
cancelAllTasks(isError) { | ||
this._tasks.forEach((task) => { | ||
task.cancel(); | ||
}); | ||
this._tasks = []; | ||
(isError ? this.logs.error : this.logs.info)('All tasks have been cancelled and removed from the tasks list.'); | ||
} | ||
} | ||
exports.TaskManager = TaskManager; |
{ | ||
"name": "@coya/task-manager", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Scheduler for run tasks successively or simultaneously", | ||
@@ -5,0 +5,0 @@ "main": "js/TaskManager.js", |
9769
-0.45%179
-2.19%