TaskHandler: bail if given a task that already has a handler

This fixes undefined behaviour when scheduling the same task twice. This is usually accidental and almost never desirable.
Note that this still allows a task to be scheduled again after it has
been cancelled; it only disallows scheduling a task multiple times
concurrently.

This commit will probably break MyPlot and other plugins that have
self-scheduling tasks, but as far as I can tell those use-cases should
be replaced with self-cancelling repeating tasks anyway.
This commit is contained in:
Dylan K. Taylor 2020-07-08 11:02:21 +01:00
parent 303344783a
commit b2249f93c0

View File

@ -55,6 +55,9 @@ class TaskHandler{
private $ownerName;
public function __construct(Task $task, int $taskId, 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;