Use constant for gracefully shutdown value
This commit is contained in:
@ -87,7 +87,7 @@ foreach ($generator as $envelope) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($stopSignalReceived) {
|
if ($stopSignalReceived) {
|
||||||
$generator->send(true); // Gracefully close connection
|
$generator->send(Subscriber::STOP); // Gracefully close connection
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -8,6 +8,8 @@ use Generator;
|
|||||||
|
|
||||||
final class Subscriber extends Reader
|
final class Subscriber extends Reader
|
||||||
{
|
{
|
||||||
|
public const STOP = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @psalm-return Generator<int, Envelope|null, true|null, void>
|
* @psalm-return Generator<int, Envelope|null, true|null, void>
|
||||||
*/
|
*/
|
||||||
@ -20,14 +22,14 @@ final class Subscriber extends Reader
|
|||||||
$message = $this->consume($timeout);
|
$message = $this->consume($timeout);
|
||||||
|
|
||||||
if (null === $message) {
|
if (null === $message) {
|
||||||
if (true === yield null) {
|
if (self::STOP === yield null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true === yield new Envelope($message, $this)) {
|
if (self::STOP === yield new Envelope($message, $this)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user