Remove TaskHandler dependency on MainLogger

This instead allows the exception to be caught by the scheduler and reported using its logger.
This commit is contained in:
Dylan K. Taylor 2018-05-30 16:00:25 +01:00
parent e20be3eeba
commit a8c766be88
2 changed files with 8 additions and 6 deletions

View File

@ -25,7 +25,6 @@ namespace pocketmine\scheduler;
use pocketmine\timings\Timings;
use pocketmine\timings\TimingsHandler;
use pocketmine\utils\MainLogger;
class TaskHandler{
@ -145,8 +144,6 @@ class TaskHandler{
if(!$this->isCancelled()){
$this->task->onCancel();
}
}catch(\Throwable $e){
MainLogger::getLogger()->logException($e);
}finally{
$this->remove();
}

View File

@ -106,14 +106,19 @@ class TaskScheduler{
*/
public function cancelTask(int $taskId){
if($taskId !== null and isset($this->tasks[$taskId])){
$this->tasks[$taskId]->cancel();
try{
$this->tasks[$taskId]->cancel();
}catch(\Throwable $e){
$this->logger->critical("Task " . $this->tasks[$taskId]->getTaskName() . " threw an exception when trying to cancel: " . $e->getMessage());
$this->logger->logException($e);
}
unset($this->tasks[$taskId]);
}
}
public function cancelAllTasks(){
foreach($this->tasks as $task){
$task->cancel();
foreach($this->tasks as $id => $task){
$this->cancelTask($id);
}
$this->tasks = [];
while(!$this->queue->isEmpty()){