diff --git a/README.md b/README.md index 8a1eb29..c5b8c5d 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ foreach ($generator as $envelope) { } if ($stopSignalReceived) { - $generator->send(true); // Gracefully close connection + $generator->send(Subscriber::STOP); // Gracefully close connection } } ``` diff --git a/src/Subscriber.php b/src/Subscriber.php index 32807cc..e280d84 100644 --- a/src/Subscriber.php +++ b/src/Subscriber.php @@ -8,6 +8,8 @@ use Generator; final class Subscriber extends Reader { + public const STOP = true; + /** * @psalm-return Generator */ @@ -20,14 +22,14 @@ final class Subscriber extends Reader $message = $this->consume($timeout); if (null === $message) { - if (true === yield null) { + if (self::STOP === yield null) { break; } continue; } - if (true === yield new Envelope($message, $this)) { + if (self::STOP === yield new Envelope($message, $this)) { break; }