Prevent send RDY every iteration

This commit is contained in:
2021-01-23 02:27:21 +03:00
parent bc276c7c57
commit 6e37bbd1ae
2 changed files with 33 additions and 22 deletions

View File

@@ -6,7 +6,6 @@ namespace Nsq;
use Generator;
use function get_debug_type;
use function microtime;
use function sprintf;
final class Subscriber
@@ -31,7 +30,7 @@ final class Subscriber
while (true) {
$this->reader->rdy(1);
$command = yield $this->consume($timeout);
$command = yield $this->reader->consume($timeout);
if (self::STOP === $command) {
break;
@@ -50,24 +49,4 @@ final class Subscriber
$this->reader->disconnect();
}
private function consume(float $timeout): ?Message
{
$deadline = microtime(true) + $timeout;
$response = $this->reader->receive($timeout);
if (null === $response) {
return null;
}
if ($response->isHeartBeat()) {
$this->reader->nop();
return $this->consume(
($currentTime = microtime(true)) > $deadline ? 0 : $deadline - $currentTime
);
}
return $response->toMessage($this->reader);
}
}