Closed ghost closed 6 years ago
You can't know whether a stream closed without reading from it.
You can throttle a stream by just not immediately keeping to read()
from it, e.g. yielding a throttling promise inside the loop.
@kelunik why not to use Emitter, I think it will be more clear when stream is closed or there is some exceptions/errors ?
@umbri Then it's the emitter that needs to read. You're free to use another stream abstraction such as ReactPHP's implementation, that's completely compatible. We don't like callbacks, that's why we have a callback-free API for streams.
@kelunik Roger that! Thanks
Typically I read from stream like this
while (($data = yield $stream->read()) !== null)
and if I have readednull
stream is closed.How can I know/find that stream is closed without read from it ? How can I throttle stream ?
P.S: I want to implement something like
pause()
,resume()
that will permit throttling, very useful for testing