-
Notifications
You must be signed in to change notification settings - Fork 232
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
Add .destroy to Readable and Writable prototypes #125
Conversation
// if this is a duplex stream mark the writable part as destroyed as well | ||
if (this._writableState) { | ||
this._writableState.destroyed = true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort of tempted to say "may as well specially implement destroy
on Duplex" just to avoid adding another case of the parent class having intimate knowledge of its subclass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea i think thats good idea. will update the pr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's almost a shame we couldn't add this to the base stream
class somehow since they are both doing pretty much the same thing.
Better still if there was a base StreamState
that all states inherited from, although that would restrict people from calling _destroy()
directly, however that might not be such a bad thing...
Curious: is the omission of |
@chrisdickinson I forgot about that :) I'll add it. |
What do you think about adding it to the construction also? e.g.: var readable = new stream.Readable({
destroy() {
// burn down the house
}
}); |
Shouldn't this be against the main io repo or is this just for discussion? |
What steps must be taken to get this into core? I'd be keen to see it land since right now |
open pull request on this repo https://github.com/nodejs/node |
I'm going to close this, an issue is where we probably want to continue this discussion. |
This is an attempt to implement #124. Basically it adds
.destroy
to the Readable and Writable prototypes. These prototypes forwards the call to._destroy(cb)
the first time destroy is called. If destroy is called twice the second call is ignored.This allows you prematurely end a stream more easily. As an example here is a file reader
Calling
rs.destroy()
will now close the file descriptor and emitclose
when the close is done.