-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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: deprecate writable/readable #29377
Comments
@mcollina What is the expected behaviour of The docs says:
I'm not sure whether this is actually true in practice and what "safe to call" means. But it does make me contemplative about how |
if the |
I've never understood |
Ok. I'll look into doc deprecating and avoid its usage in core once the number of PRs go down. |
The properties are useful for immediately determining the possibility of reading/writing from/to a stream. If you're the one creating the streams, sure, you can listen for events. However if you're writing a third party module that accepts streams, you have no idea if you were just passed a stream that is not usable in its current state. |
I guess that's the theory... but I don't think it actually works like that in practice, e.g. a Also I think (if I remember correctly) there are some possible inconsistencies in regards to |
I guess the question is... should we deprecate, document or fix? |
Shouldn't a stream always be |
I disagree. For example, if I have a network protocol module that accepts a user-supplied |
I'm having trouble following that reasoning. What does it have to do with |
If I'm handed an arbitrary stream, I want to know immediately if calling
I'm not sure what you mean by this. From a stream consumer perspective, I'm not in control of that. From a stream creator perspective, with
Here are a few issues with a 'destroyed' stream:
|
This is way over my head. I'll defer to your expertise. At some point it would be nice to have this described in the documentation at the least. Anyhow, I believe the way |
In this case the stream should already be
True, but not sure if relevant.
Not true. This is handled by the
"undestroy" is a weird quirk we should probably deprecate. It's only used by I feel you might be right though about readable/writable in the case of |
@mscdex: I think I feel a bit more confident with streams at this point and wouldn't mind continuing this discussion if you are still up for it. |
I think we might want to keep defineProperty(Writable.prototype, 'writable', {
get() {
const w = this._writableState;
if (w && typeof w[kWritable] === 'boolean') return w[kWritable];
return w && !w.errored && !w.destroyed && !w.ended;
},
set(val) {
// Backwards compat.
const w = this._writableState;
w[kWritable] = val;
}
});
defineProperty(Readable.prototype, 'readable', {
get() {
const r = this._readableState;
if (r && typeof r[kReadable] === 'boolean') return r[kReadable];
return r && !r.errored && !r.destroyed && !r.ended;
},
set(val) {
// Backwards compat.
const r = this._readableState;
r[kReadable] = val;
}
}); Or something along those lines. This would be make these much more consistent and easier to reason about what they mean and what they do. @mcollina: What do you think? Does something like that make sense at least in theory? @jasnell: I noticed you were using |
We can’t remove the setter fir backward compat. I like the idea of the getter. |
This comment has been minimized.
This comment has been minimized.
This makes readable and writable automatically computed based on the stream state. Effectivly deprecating/discouraging manual management of this. Makes the properties more consistent and easier to reason about. Fixes: nodejs#29377
EDIT: Updated description. Old description remains below.
fastify/fastify#1833 is also relevant.
The text was updated successfully, but these errors were encountered: