Skip to content

Commit

Permalink
PendingReadException → PendingReadError
Browse files Browse the repository at this point in the history
Consecutive reads is a coding error, so it should be an instance of Error.
  • Loading branch information
trowski committed May 12, 2017
1 parent f6e765c commit e7f7326
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
3 changes: 1 addition & 2 deletions lib/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Amp\Coroutine;
use Amp\Deferred;
use Amp\Failure;
use Amp\Iterator;
use Amp\Promise;
use Amp\Success;
Expand Down Expand Up @@ -85,7 +84,7 @@ private function iterate(Iterator $iterator): \Generator {

public function read(): Promise {
if ($this->pendingRead) {
return new Failure(new PendingReadException);
throw new PendingReadError;
}

if ($this->buffer !== "") {
Expand Down
10 changes: 4 additions & 6 deletions lib/PendingReadException.php → lib/PendingReadError.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

namespace Amp\ByteStream;

use Throwable;

/**
* Thrown in case a second read operation is attempted while another read operation is still pending.
*/
class PendingReadException extends StreamException {
class PendingReadError extends \Error {
public function __construct(
$message = "The previous read operation must complete before read can be called again",
$code = 0,
Throwable $previous = null
string $message = "The previous read operation must complete before read can be called again",
int $code = 0,
\Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
Expand Down
5 changes: 2 additions & 3 deletions lib/ResourceInputStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Amp\ByteStream;

use Amp\Deferred;
use Amp\Failure;
use Amp\Loop;
use Amp\Promise;
use Amp\Success;
Expand Down Expand Up @@ -80,11 +79,11 @@ public function __construct($stream, int $chunkSize = self::DEFAULT_CHUNK_SIZE)
*
* @return Promise Resolves with a string when new data is available or `null` if the stream has closed.
*
* @throws PendingReadException Thrown if another read operation is still pending.
* @throws PendingReadError Thrown if another read operation is still pending.
*/
public function read(): Promise {
if ($this->deferred !== null) {
throw new PendingReadException;
throw new PendingReadError;
}

if (!$this->readable) {
Expand Down

0 comments on commit e7f7326

Please sign in to comment.