-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
stream: add isFlowing
method
#451
Conversation
Add `isFlowing` method to detect if readable stream is in a flowing mode. `!isPaused()` is not enough since there is a third "initial" state.
This PR should prob be submitted to https://github.com/iojs/readable-stream also |
@sonewman readable-stream currently has a script for slurping up changes from upstream repos. Until we've got that flow reversed, this repo is still the correct place for streams PRs. |
Hm, I am a little conflicted here. Should |
( |
Well we have function doSomethingWithAStream(stream) {
stream.on('data', ...); // can accidentally switch into flowing mode
}
function doSomethingElseWithAStream(stream) {
var flowing = stream.isFlowing();
stream.on('data', ...); // can accidentally switch into flowing mode
if (!flowing) stream.pause();
}
If it's public then more things can be done in userland. That's the point of this issue. If doing something requires knowledge about internals, that means that some things a just impossible to implement outside of the core. |
@chrisdickinson I agree it should be on the |
@vkurchatkin What I meant to say was: "I added Re: the code example: that API is attainable at present through the somewhat-roundabout |
Definitely +1 on that. But I can only imagine how painful it would be. |
@chrisdickinson would that mean that you would need to explicitly called It would mean the implementer would need to document the use of the module more throughly in order for consumers to known what to expect. |
@sonewman I'm not sure how I feel about making all kinds of flowing explicit like that – that bears more thought than I've given it. I mean that we'd nix |
this looks like a totally separate issue. I can see no real purpose of that, but it definitely makes things difficult (like we have to |
@vkurchatkin this is currently how the readable stream works. The null value is the initial state _stream_readable.js#L83. If you add a data handle and this value is null then it starts flowing mode _stream_readable.js#L707-L709. If you call pause it will set This means that if you call This is where the tri-value comes from. @chrisdickinson is suggesting simplifying that API to make the control more explicit and remove the tri-value state. |
@sonewman what I mean is, we can remove "tri-value state" right away. It only affects the result of |
@vkurchatkin it would definitely be a breaking change, all streams using the on |
we have "semver-minor" and "semver-major" tags now, can someone decide what this is (if any) and tag this please? |
@rvagg this should be semver-minor, but I'm just going to close it |
Add
isFlowing
method to detect if readable stream is in a flowing mode.!isPaused()
is not enough since there is a third "initial" state.see #445
/cc @chrisdickinson