2020-12-12 02:11:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Toalett\Multiprocessing\Task;
|
|
|
|
|
|
|
|
use React\EventLoop\LoopInterface;
|
|
|
|
|
|
|
|
class Tasks
|
|
|
|
{
|
2020-12-12 13:05:48 +01:00
|
|
|
/** @var Task[] */
|
|
|
|
private array $tasks;
|
|
|
|
private ?LoopInterface $loop = null;
|
2020-12-12 02:11:05 +01:00
|
|
|
|
2020-12-12 13:05:48 +01:00
|
|
|
public function __construct(Task ...$tasks)
|
|
|
|
{
|
|
|
|
$this->tasks = $tasks;
|
|
|
|
}
|
2020-12-12 02:11:05 +01:00
|
|
|
|
2020-12-12 13:05:48 +01:00
|
|
|
public function enable(LoopInterface $loop): void
|
|
|
|
{
|
|
|
|
if (is_null($this->loop)) {
|
|
|
|
$this->loop = $loop;
|
|
|
|
foreach ($this->tasks as $task) {
|
|
|
|
$task->enable($this->loop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-12 02:11:05 +01:00
|
|
|
|
2020-12-12 13:05:48 +01:00
|
|
|
public function cancel(): void
|
|
|
|
{
|
|
|
|
if (!is_null($this->loop)) {
|
|
|
|
foreach ($this->tasks as $task) {
|
|
|
|
$task->cancel($this->loop);
|
|
|
|
}
|
|
|
|
$this->loop = null;
|
|
|
|
}
|
|
|
|
}
|
2020-12-12 02:11:05 +01:00
|
|
|
}
|