1
0
mirror of https://github.com/danog/byte-stream.git synced 2024-11-30 04:19:23 +01:00

Return Failure instead of throwing

Closure should fail returned promise, not throw directly from method call.
This commit is contained in:
Aaron Piotrowski 2019-07-26 16:22:49 -05:00
parent 22113f2f14
commit 47908f8e8b
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
2 changed files with 4 additions and 2 deletions

View File

@ -17,6 +17,7 @@ interface OutputStream
* @return Promise Succeeds once the data has been successfully written to the stream.
*
* @throws ClosedException If the stream has already been closed.
* @throws StreamException If writing to the stream fails.
*/
public function write(string $data): Promise;
@ -30,6 +31,7 @@ interface OutputStream
* @return Promise Succeeds once the data has been successfully written to the stream.
*
* @throws ClosedException If the stream has already been closed.
* @throws StreamException If writing to the stream fails.
*/
public function end(string $finalData = ""): Promise;
}

View File

@ -72,7 +72,7 @@ final class ResourceOutputStream implements OutputStream
}
if (!\is_resource($stream) || (($metaData = @\stream_get_meta_data($stream)) && $metaData['eof'])) {
throw new StreamException("The stream was closed by the peer");
throw new ClosedException("The stream was closed by the peer");
}
// Error reporting suppressed since fwrite() emits E_WARNING if the pipe is broken or the buffer is full.
@ -180,7 +180,7 @@ final class ResourceOutputStream implements OutputStream
}
if (!\is_resource($this->resource) || (($metaData = @\stream_get_meta_data($this->resource)) && $metaData['eof'])) {
throw new StreamException("The stream was closed by the peer");
return new Failure(new ClosedException("The stream was closed by the peer"));
}
// Error reporting suppressed since fwrite() emits E_WARNING if the pipe is broken or the buffer is full.