scheduler: removing task IDs

These no longer serve any purpose that can't be replaced with a structure like Ds\Set, SplObjectStorage, or just using spl_object_id().
This commit is contained in:
Dylan K. Taylor 2020-07-08 12:01:48 +01:00
parent d738504e24
commit 6bca38999d
3 changed files with 2 additions and 26 deletions

View File

@ -37,14 +37,6 @@ abstract class Task{
return $this->taskHandler;
}
final public function getTaskId() : int{
if($this->taskHandler !== null){
return $this->taskHandler->getTaskId();
}
return -1;
}
public function getName() : string{
return Utils::getNiceClassName($this);
}

View File

@ -31,9 +31,6 @@ class TaskHandler{
/** @var Task */
protected $task;
/** @var int */
protected $taskId;
/** @var int */
protected $delay;
@ -54,12 +51,11 @@ class TaskHandler{
/** @var string */
private $ownerName;
public function __construct(Task $task, int $taskId, int $delay = -1, int $period = -1, ?string $ownerName = null){
public function __construct(Task $task, int $delay = -1, int $period = -1, ?string $ownerName = null){
if($task->getHandler() !== null){
throw new \InvalidArgumentException("Cannot assign multiple handlers to the same task");
}
$this->task = $task;
$this->taskId = $taskId;
$this->delay = $delay;
$this->period = $period;
$this->taskName = $task->getName();
@ -80,10 +76,6 @@ class TaskHandler{
$this->nextRun = $ticks;
}
public function getTaskId() : int{
return $this->taskId;
}
public function getTask() : Task{
return $this->task;
}

View File

@ -49,9 +49,6 @@ class TaskScheduler{
*/
protected $tasks;
/** @var int */
private $ids = 1;
/** @var int */
protected $currentTick = 0;
@ -85,7 +82,6 @@ class TaskScheduler{
while(!$this->queue->isEmpty()){
$this->queue->extract();
}
$this->ids = 1;
}
public function isQueued(TaskHandler $task) : bool{
@ -110,7 +106,7 @@ class TaskScheduler{
$period = 1;
}
return $this->handle(new TaskHandler($task, $this->nextId(), $delay, $period, $this->owner));
return $this->handle(new TaskHandler($task, $delay, $period, $this->owner));
}
private function handle(TaskHandler $handler) : TaskHandler{
@ -159,8 +155,4 @@ class TaskScheduler{
private function isReady(int $currentTick) : bool{
return !$this->queue->isEmpty() and $this->queue->current()->getNextRun() <= $currentTick;
}
private function nextId() : int{
return $this->ids++;
}
}