Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InputStream throttling #36

Closed
ghost opened this issue Mar 6, 2018 · 4 comments
Closed

InputStream throttling #36

ghost opened this issue Mar 6, 2018 · 4 comments
Labels

Comments

@ghost
Copy link

ghost commented Mar 6, 2018

Typically I read from stream like this while (($data = yield $stream->read()) !== null) and if I have readed null 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

@kelunik
Copy link
Member

kelunik commented Mar 6, 2018

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 kelunik changed the title [question] InputStream InputStream throttling Mar 6, 2018
@ghost
Copy link
Author

ghost commented Mar 6, 2018

@kelunik why not to use Emitter, I think it will be more clear when stream is closed or there is some exceptions/errors ?

@kelunik
Copy link
Member

kelunik commented Mar 6, 2018

@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.

@ghost
Copy link
Author

ghost commented Mar 6, 2018

@kelunik Roger that! Thanks

@ghost ghost closed this as completed Mar 6, 2018
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant