Skip to content

Instantly share code, notes, and snippets.

@JackNoordhuis
Created February 9, 2020 07:01
Show Gist options
  • Save JackNoordhuis/936df0444262d10538239c0e985f7d04 to your computer and use it in GitHub Desktop.
Save JackNoordhuis/936df0444262d10538239c0e985f7d04 to your computer and use it in GitHub Desktop.
Script plugin for testing PocketMine async worker init closures.
<?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