php-ipc/src/Interop/Bus/Master.php

40 lines
825 B
PHP

<?php
namespace NoccyLabs\Ipc\Interop\Bus;
use NoccyLabs\Ipc\Interop\Channel\ChannelInterface;
use NoccyLabs\Ipc\Interop\Channel\MultiStreamChannel;
use NoccyLabs\Ipc\Interop\Async\Timer;
class Master
{
/** @var ChannelInterface $channel */
protected $channel;
/**
* Constructor
*/
public function __construct()
{
$this->channel = new MultiStreamChannel();
$this->timer = new Timer([ $this, "update" ]);
}
public function createClient() : Client
{
/** @var ChannelInterface $channel */
$channel = $this->channel->createClient();
$client = new Client($channel);
return $client;
}
public function update()
{
while ($msg = $this->channel->receive()) {
$this->channel->send($msg);
}
}
}