mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-29 06:05:54 +00:00
Thread/Worker run() are now final, to set up common environment things
This commit is contained in:
parent
e07f3e8e65
commit
44c791f03e
@ -23,6 +23,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine;
|
||||
|
||||
use function error_reporting;
|
||||
|
||||
/**
|
||||
* This class must be extended by all custom threading classes
|
||||
*/
|
||||
@ -73,6 +75,19 @@ abstract class Thread extends \Thread{
|
||||
return parent::start($options);
|
||||
}
|
||||
|
||||
final public function run() : void{
|
||||
error_reporting(-1);
|
||||
$this->registerClassLoader();
|
||||
//set this after the autoloader is registered
|
||||
\ErrorUtils::setErrorExceptionHandler();
|
||||
$this->onRun();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs code on the thread.
|
||||
*/
|
||||
abstract protected function onRun() : void;
|
||||
|
||||
/**
|
||||
* Stops the thread using the best way possible. Try to stop it yourself before calling this.
|
||||
*/
|
||||
|
@ -23,6 +23,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine;
|
||||
|
||||
use function error_reporting;
|
||||
|
||||
/**
|
||||
* This class must be extended by all custom threading classes
|
||||
*/
|
||||
@ -73,6 +75,17 @@ abstract class Worker extends \Worker{
|
||||
return parent::start($options);
|
||||
}
|
||||
|
||||
final public function run() : void{
|
||||
error_reporting(-1);
|
||||
$this->registerClassLoader();
|
||||
$this->onRun();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs code on the thread.
|
||||
*/
|
||||
abstract protected function onRun() : void;
|
||||
|
||||
/**
|
||||
* Stops the thread using the best way possible. Try to stop it yourself before calling this.
|
||||
*/
|
||||
|
@ -184,9 +184,7 @@ class CommandReader extends Thread{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function run() : void{
|
||||
$this->registerClassLoader();
|
||||
|
||||
protected function onRun() : void{
|
||||
if($this->type !== self::TYPE_READLINE){
|
||||
$this->initStdin();
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ namespace pocketmine\scheduler;
|
||||
|
||||
use pocketmine\utils\MainLogger;
|
||||
use pocketmine\Worker;
|
||||
use function error_reporting;
|
||||
use function gc_enable;
|
||||
use function ini_set;
|
||||
|
||||
@ -45,14 +44,7 @@ class AsyncWorker extends Worker{
|
||||
$this->memoryLimit = $memoryLimit;
|
||||
}
|
||||
|
||||
public function run() : void{
|
||||
error_reporting(-1);
|
||||
|
||||
$this->registerClassLoader();
|
||||
|
||||
//set this after the autoloader is registered
|
||||
\ErrorUtils::setErrorExceptionHandler();
|
||||
|
||||
protected function onRun() : void{
|
||||
\GlobalLogger::set($this->logger);
|
||||
if($this->logger instanceof MainLogger){
|
||||
$this->logger->registerStatic();
|
||||
|
@ -38,8 +38,7 @@ class ServerKiller extends Thread{
|
||||
$this->time = $time;
|
||||
}
|
||||
|
||||
public function run() : void{
|
||||
$this->registerClassLoader();
|
||||
protected function onRun() : void{
|
||||
$start = time();
|
||||
$this->synchronized(function(){
|
||||
if(!$this->stopped){
|
||||
|
Loading…
x
Reference in New Issue
Block a user