scheduleTask(new CancellableClosureTask(function(int $currentTick) : bool{ * echo "HI on $currentTick\n"; * $continue = false; * return $continue; //stop repeating * }); * ``` * * @see ClosureTask */ class CancellableClosureTask extends Task{ public const CONTINUE = true; public const CANCEL = false; /** @var \Closure */ private $closure; /** * CancellableClosureTask constructor. * * The closure should follow the signature callback(int $currentTick) : bool. The return value will be used to * decide whether to continue repeating. * * @param \Closure $closure */ public function __construct(\Closure $closure){ Utils::validateCallableSignature(function(int $currentTick) : bool{ return false; }, $closure); $this->closure = $closure; } public function getName() : string{ return Utils::getNiceClosureName($this->closure); } public function onRun(int $currentTick) : void{ if(!($this->closure)($currentTick)){ $this->getHandler()->cancel(); } } }