reader = $reader; } /** * @psalm-return Generator */ public function subscribe(string $topic, string $channel, float $timeout = 0): Generator { $this->reader->sub($topic, $channel); while (true) { $this->reader->rdy(1); $command = yield $this->reader->consume($timeout); if (self::STOP === $command) { break; } if (self::CHANGE_TIMEOUT === $command) { $newTimeout = yield null; if (!\is_float($newTimeout)) { throw new InvalidArgumentException(sprintf('Timeout must be float, "%s" given.', get_debug_type($newTimeout))); } $timeout = $newTimeout; } if (self::TIMEOUT === $command) { yield $timeout; } } $this->reader->disconnect(); } }