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