amphp / byte-stream

A non-blocking stream abstraction for PHP based on Amp.

Home Page:https://amphp.org/byte-stream

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use ClosedError instead of ClosedException

bwoebi opened this issue · comments

It's clearly an Error, as it only occurs if you explicitly closed a stream and then still try to operate on it.

(Please fix in the next major to be released.)

@bwoebi In fact this is not true. While it is true for file handles, it is not true for TCP streams.

I thought on TCP streams, we just resolve with null if the stream is closed by the peer?!

@bwoebi For reading, yes, but not for writing.

@bwoebi Can I close this one? I don't think we need ClosedException and ClosedError.

We do need it. The one you may want to catch, the other most definitely not. (write to closed peer)
It is prone to hiding bugs otherwise.

I vote to close this. Writing to a closed peer might totally happen if you have a writing coroutine and close the stream from somewhere else, e.g. the reading coroutine. Having to add an extra flag or catching ClosedError is just horrible.