1
0
mirror of https://github.com/danog/byte-stream.git synced 2024-11-26 20:04:51 +01:00

Make Parser + PendingReadError final, add explicit note about extension to Message

This commit is contained in:
Niklas Keller 2017-05-25 17:30:53 +02:00
parent 6bc8199340
commit 21945b888f
3 changed files with 7 additions and 5 deletions

View File

@ -11,6 +11,9 @@ use Amp\Success;
* Creates a buffered message from an InputStream. The message can be consumed in chunks using the read() API or it may
* be buffered and accessed in its entirety by waiting for the promise to resolve.
*
* Other implementations may extend this class to add custom properties such as a `isBinary()` flag for WebSocket
* messages.
*
* Buffering Example:
*
* $stream = new Message($inputStream);
@ -84,6 +87,7 @@ class Message implements InputStream, Promise {
return $this->buffer;
}
/** @inheritdoc */
final public function read(): Promise {
if ($this->pendingRead) {
throw new PendingReadError;
@ -114,9 +118,7 @@ class Message implements InputStream, Promise {
return $this->pendingRead->promise();
}
/**
* {@inheritdoc}
*/
/** @inheritdoc */
final public function onResolve(callable $onResolved) {
$this->buffering = true;

View File

@ -7,7 +7,7 @@ use Amp\InvalidYieldError;
use Amp\Promise;
use Amp\Success;
class Parser implements OutputStream {
final class Parser implements OutputStream {
/** @var \Generator */
private $generator;

View File

@ -5,7 +5,7 @@ namespace Amp\ByteStream;
/**
* Thrown in case a second read operation is attempted while another read operation is still pending.
*/
class PendingReadError extends \Error {
final class PendingReadError extends \Error {
public function __construct(
string $message = "The previous read operation must complete before read can be called again",
int $code = 0,