Remove Subscriber
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Nsq;
|
||||
|
||||
use Generator;
|
||||
use Nsq\Config\ClientConfig;
|
||||
use Nsq\Exception\NsqError;
|
||||
use Nsq\Exception\NsqException;
|
||||
@@ -34,6 +35,24 @@ final class Consumer extends Connection
|
||||
$this->command('SUB', [$this->topic, $this->channel])->checkIsOK();
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-return Generator<int, Message|float|null, int|null, void>
|
||||
*/
|
||||
public function generator(): Generator
|
||||
{
|
||||
while (true) {
|
||||
$this->rdy(1);
|
||||
|
||||
$command = yield $this->readMessage();
|
||||
|
||||
if (0 === $command) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->disconnect();
|
||||
}
|
||||
|
||||
public function readMessage(): ?Message
|
||||
{
|
||||
$frame = $this->readFrame();
|
||||
|
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Nsq;
|
||||
|
||||
use Generator;
|
||||
use Nsq\Protocol\Message;
|
||||
|
||||
final class Subscriber
|
||||
{
|
||||
public const STOP = 0;
|
||||
|
||||
private Consumer $reader;
|
||||
|
||||
public function __construct(Consumer $reader)
|
||||
{
|
||||
$this->reader = $reader;
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-return Generator<int, Message|float|null, int|null, void>
|
||||
*/
|
||||
public function run(): Generator
|
||||
{
|
||||
while (true) {
|
||||
$this->reader->rdy(1);
|
||||
|
||||
$command = yield $this->reader->readMessage();
|
||||
|
||||
if (self::STOP === $command) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->reader->disconnect();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user