-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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 destroy and _destroy methods. #12925
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,6 +194,14 @@ Transform.prototype._read = function(n) { | |
}; | ||
|
||
|
||
Transform.prototype._destroy = function(err, cb) { | ||
Duplex.prototype._destroy.call(this, err, (err2) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are not inheriting with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that matters edit: according to mdn it doesn't. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @calvinmetcalf it doesn't work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right only for object shorthand syntax my bad. |
||
cb(err2); | ||
this.emit('close'); | ||
}); | ||
}; | ||
|
||
|
||
function done(stream, er, data) { | ||
if (er) | ||
return stream.emit('error', er); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
'use strict'; | ||
|
||
// undocumented cb() API, needed for core, not for public API | ||
function destroy(err, cb) { | ||
const readableDestroyed = this._readableState && | ||
this._readableState.destroyed; | ||
const writableDestroyed = this._writableState && | ||
this._writableState.destroyed; | ||
|
||
if (readableDestroyed || writableDestroyed) { | ||
if (err && (!this._writableState || !this._writableState.errorEmitted)) { | ||
process.nextTick(emitErrorNT, this, err); | ||
} | ||
return; | ||
} | ||
|
||
// we set destroyed to true before firing error callbacks in order | ||
// to make it re-entrance safe in case destroy() is called within callbacks | ||
|
||
if (this._readableState) { | ||
this._readableState.destroyed = true; | ||
} | ||
|
||
// if this is a duplex stream mark the writable part as destroyed as well | ||
if (this._writableState) { | ||
this._writableState.destroyed = true; | ||
} | ||
|
||
this._destroy(err || null, (err) => { | ||
if (!cb && err) { | ||
process.nextTick(emitErrorNT, this, err); | ||
if (this._writableState) { | ||
this._writableState.errorEmitted = true; | ||
} | ||
} else if (cb) { | ||
cb(err); | ||
} | ||
}); | ||
} | ||
|
||
function undestroy() { | ||
if (this._readableState) { | ||
this._readableState.destroyed = false; | ||
this._readableState.reading = false; | ||
this._readableState.ended = false; | ||
this._readableState.endEmitted = false; | ||
} | ||
|
||
if (this._writableState) { | ||
this._writableState.destroyed = false; | ||
this._writableState.ended = false; | ||
this._writableState.ending = false; | ||
this._writableState.finished = false; | ||
this._writableState.errorEmitted = false; | ||
} | ||
} | ||
|
||
function emitErrorNT(self, err) { | ||
self.emit('error', err); | ||
} | ||
|
||
module.exports = { | ||
destroy, | ||
undestroy | ||
}; |
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.
The newly added APIs should probably have changelogs.