source = $inputStream; } /** * @return Promise */ public function readLine(): Promise { return call(function () { while (null !== $chunk = yield $this->source->read()) { $this->buffer .= $chunk; if (($pos = \strpos($this->buffer, "\n")) !== false) { $line = \substr($this->buffer, 0, $pos); $this->buffer = \substr($this->buffer, $pos + 1); return \rtrim($line, "\r"); } } if ($this->buffer === "") { return null; } if (($pos = \strpos($this->buffer, "\n")) !== false) { $line = \substr($this->buffer, 0, $pos); $this->buffer = \substr($this->buffer, $pos + 1); return \rtrim($line, "\r"); } $line = $this->buffer; $this->buffer = ""; return \rtrim($line, "\r"); }); } }