Add signature validation for some user-defined callbacks

This commit is contained in:
Dylan K. Taylor 2018-12-04 18:33:58 +00:00
parent 762405d16a
commit a95694ed06
2 changed files with 3 additions and 0 deletions

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\scheduler; namespace pocketmine\scheduler;
use pocketmine\Server; use pocketmine\Server;
use pocketmine\utils\Utils;
/** /**
* Manages general-purpose worker threads used for processing asynchronous tasks, and the tasks submitted to those * Manages general-purpose worker threads used for processing asynchronous tasks, and the tasks submitted to those
@ -96,6 +97,7 @@ class AsyncPool{
* @param \Closure $hook * @param \Closure $hook
*/ */
public function addWorkerStartHook(\Closure $hook) : void{ public function addWorkerStartHook(\Closure $hook) : void{
Utils::validateCallableSignature(function(int $worker) : void{}, $hook);
$this->workerStartHooks[spl_object_hash($hook)] = $hook; $this->workerStartHooks[spl_object_hash($hook)] = $hook;
foreach($this->workers as $i => $worker){ foreach($this->workers as $i => $worker){
$hook($i); $hook($i);

View File

@ -45,6 +45,7 @@ class ClosureTask extends Task{
* @param \Closure $closure Must accept only ONE parameter, $currentTick * @param \Closure $closure Must accept only ONE parameter, $currentTick
*/ */
public function __construct(\Closure $closure){ public function __construct(\Closure $closure){
Utils::validateCallableSignature(function(int $currentTick) : void{}, $closure);
$this->closure = $closure; $this->closure = $closure;
} }