Skip to content

Commit

Permalink
allow definition of init task after adding workers
Browse files Browse the repository at this point in the history
  • Loading branch information
matthi4s committed Jul 10, 2024
1 parent f89230a commit 9a17344
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Taskmaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,10 @@ public function setDefaultInitTask(TaskInterface|string $task): static
$this->initTaskFactory = new CloneTaskFactory($task);
}

foreach ($this->workers as $worker) {
$worker->setInitTaskFactoryIfNecessary($this->initTaskFactory);
}

return $this;
}

Expand Down
16 changes: 16 additions & 0 deletions test/Integration/AsyncWorkerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,20 @@ public function testInitTask(): void
}
$this->assertEquals(3, $counter);
}

public function testInitTaskAfterWorkerCreation(): void
{
$this->taskmaster = new Taskmaster();
$this->taskmaster->addWorkers($this->createWorker(), 3);
$this->taskmaster->setDefaultInitTask(InitTask::class);

$this->addTasks(new InitValidateTask(), 3);
$counter = 0;
foreach ($this->taskmaster->waitAndHandleTasks() as $task) {
$this->assertNull($task->getError());
$this->assertTrue($task->getResult());
$counter++;
}
$this->assertEquals(3, $counter);
}
}

0 comments on commit 9a17344

Please sign in to comment.