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:
parent
22113f2f14
commit
47908f8e8b
@ -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;
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user