diff --git a/src/thread/CommonThreadPartsTrait.php b/src/thread/CommonThreadPartsTrait.php index f01a979b0..9cd2b68f9 100644 --- a/src/thread/CommonThreadPartsTrait.php +++ b/src/thread/CommonThreadPartsTrait.php @@ -120,6 +120,20 @@ trait CommonThreadPartsTrait{ $this->isKilled = true; } + /** + * Stops the thread using the best way possible. Try to stop it yourself before calling this. + */ + public function quit() : void{ + $this->isKilled = true; + + if(!$this->isJoined()){ + $this->notify(); + $this->join(); + } + + ThreadManager::getInstance()->remove($this); + } + /** * Called by set_exception_handler() when an uncaught exception is thrown. */ diff --git a/src/thread/Thread.php b/src/thread/Thread.php index 2f0204022..a6c36e14c 100644 --- a/src/thread/Thread.php +++ b/src/thread/Thread.php @@ -37,18 +37,4 @@ use pocketmine\scheduler\AsyncTask; */ abstract class Thread extends NativeThread{ use CommonThreadPartsTrait; - - /** - * Stops the thread using the best way possible. Try to stop it yourself before calling this. - */ - public function quit() : void{ - $this->isKilled = true; - - if(!$this->isJoined()){ - $this->notify(); - $this->join(); - } - - ThreadManager::getInstance()->remove($this); - } } diff --git a/src/thread/Worker.php b/src/thread/Worker.php index 7d9ca72c3..cc0b56046 100644 --- a/src/thread/Worker.php +++ b/src/thread/Worker.php @@ -38,21 +38,4 @@ use pocketmine\scheduler\AsyncTask; */ abstract class Worker extends NativeWorker{ use CommonThreadPartsTrait; - - /** - * Stops the thread using the best way possible. Try to stop it yourself before calling this. - */ - public function quit() : void{ - $this->isKilled = true; - - if(!$this->isShutdown()){ - $this->synchronized(function() : void{ - while($this->unstack() !== null); - }); - $this->notify(); - $this->shutdown(); - } - - ThreadManager::getInstance()->remove($this); - } }