%PDF- %GIF98; %PNG;
Server : ApacheSystem : Linux host.digitalbabaji.in 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64 User : addictionfreeind ( 1003) PHP Version : 7.2.34 Disable Function : exec,passthru,shell_exec,system Directory : /home/addictionfreeind/www/admin1/vendor/amphp/parallel/lib/Context/Internal/ |
Upload File : |
<?php
namespace Amp\Parallel\Context\Internal;
use Amp\Loop;
use Amp\Parallel\Sync\ChannelledSocket;
use parallel\Events;
use parallel\Future;
class ParallelHub extends ProcessHub
{
const EXIT_CHECK_FREQUENCY = 250;
/** @var ChannelledSocket[] */
private $channels;
/** @var string */
private $watcher;
/** @var Events */
private $events;
public function __construct()
{
parent::__construct();
$events = $this->events = new Events;
$this->events->setBlocking(false);
$channels = &$this->channels;
$this->watcher = Loop::repeat(self::EXIT_CHECK_FREQUENCY, static function () use (&$channels, $events): void {
while ($event = $events->poll()) {
$id = (int) $event->source;
\assert(isset($channels[$id]), 'Channel for context ID not found');
$channel = $channels[$id];
unset($channels[$id]);
$channel->close();
}
});
Loop::disable($this->watcher);
Loop::unreference($this->watcher);
}
public function add(int $id, ChannelledSocket $channel, Future $future): void
{
$this->channels[$id] = $channel;
$this->events->addFuture((string) $id, $future);
Loop::enable($this->watcher);
}
public function remove(int $id): void
{
if (!isset($this->channels[$id])) {
return;
}
unset($this->channels[$id]);
$this->events->remove((string) $id);
if (empty($this->channels)) {
Loop::disable($this->watcher);
}
}
}