Nats\Connection::wait PHP Method

wait() public method

Waits for messages.
public wait ( integer $quantity ) : resource
$quantity integer Number of messages to wait for.
return resource $connection Connection object
    public function wait($quantity = 0)
    {
        $count = 0;
        $info = stream_get_meta_data($this->streamSocket);
        while (is_resource($this->streamSocket) && !feof($this->streamSocket) && !$info['timed_out']) {
            $line = $this->receive();
            if ($line === false) {
                return null;
            }
            if (strpos($line, 'PING') === 0) {
                $this->handlePING();
            }
            if (strpos($line, 'MSG') === 0) {
                $count = $count + 1;
                $this->handleMSG($line);
                if ($quantity != 0 && $count >= $quantity) {
                    return $this;
                }
            }
            $info = stream_get_meta_data($this->streamSocket);
        }
        $this->close();
        return $this;
    }