toalett-multiprocessing/src/Task/Tasks.php

38 lines
763 B
PHP
Raw Normal View History

2020-12-12 02:11:05 +01:00
<?php
namespace Toalett\Multiprocessing\Task;
use React\EventLoop\LoopInterface;
class Tasks
{
/** @var Task[] */
private array $tasks;
private ?LoopInterface $loop = null;
2020-12-12 02:11:05 +01:00
public function __construct(Task ...$tasks)
{
$this->tasks = $tasks;
}
2020-12-12 02:11:05 +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
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
}