mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
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:
parent
e20be3eeba
commit
a8c766be88
@ -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();
|
||||
}
|
||||
|
@ -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()){
|
||||
|
Loading…
x
Reference in New Issue
Block a user