30 protected int $nextRun;
32 protected bool $cancelled =
false;
36 private string $taskName;
37 private string $ownerName;
39 public function __construct(
41 protected int $delay = -1,
42 protected int $period = -1,
43 ?
string $ownerName =
null
45 if($task->getHandler() !==
null){
46 throw new \InvalidArgumentException(
"Cannot assign multiple handlers to the same task");
48 $this->taskName = $task->getName();
49 $this->ownerName = $ownerName ??
"Unknown";
50 $this->timings = Timings::getScheduledTaskTimings($this, $period);
51 $this->task->setHandler($this);
54 public function isCancelled() :
bool{
55 return $this->cancelled;
58 public function getNextRun() :
int{
59 return $this->nextRun;
65 public function setNextRun(
int $ticks) :
void{
66 $this->nextRun = $ticks;
69 public function getTask() :
Task{
73 public function getDelay() :
int{
77 public function isDelayed() :
bool{
78 return $this->delay > 0;
81 public function isRepeating() :
bool{
82 return $this->period > 0;
85 public function getPeriod() :
int{
89 public function cancel() :
void{
91 if(!$this->isCancelled()){
92 $this->task->onCancel();
102 public function remove() :
void{
103 $this->cancelled =
true;
104 $this->task->setHandler(
null);
110 public function run() :
void{
111 $this->timings->startTiming();
113 $this->task->onRun();
117 $this->timings->stopTiming();
121 public function getTaskName() :
string{
122 return $this->taskName;
125 public function getOwnerName() :
string{
126 return $this->ownerName;