Created
February 9, 2020 07:01
-
-
Save JackNoordhuis/936df0444262d10538239c0e985f7d04 to your computer and use it in GitHub Desktop.
Script plugin for testing PocketMine async worker init closures.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @name TestAsyncPoolInitClosures | |
* @main jacknoordhuis\test\TestAsyncPoolInitClosures | |
* @version 1.0.0 | |
* @api 4.0.0 | |
* @author Jack Noordhuis | |
*/ | |
declare(strict_types=1); | |
namespace jacknoordhuis\test { | |
use GlobalLogger; | |
use pocketmine\event\Listener; | |
use pocketmine\plugin\PluginBase; | |
class TestAsyncPoolInitClosures extends PluginBase implements Listener { | |
protected function onEnable() { | |
// will log the message to any existing workers | |
$this->getServer()->getAsyncPool()->addWorkerInitHook($closure = function() : void { | |
/** @var $this \pocketmine\scheduler\AsyncTask */ | |
GlobalLogger::get()->info("async worker init closure"); | |
}); | |
// the message will not be logged on any new workers | |
$this->getServer()->getAsyncPool()->removeWorkerInitHook($closure); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment