http: replace finish() callback with arrow function
Take advantage of arrow function lexical `this` to avoid defining a `self = this` var which was only used once. Code relating to the `finish` event was split in to two areas of the parent function. Gathered it together to clarify association within the script. Fixes: https://github.com/nodejs/node/issues/7295 PR-URL: https://github.com/nodejs/node/pull/7378 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
926707f0a7
commit
3c09d1b55f
@ -546,14 +546,6 @@ OutgoingMessage.prototype.end = function(data, encoding, callback) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
|
||||||
function finish() {
|
|
||||||
self.emit('finish');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof callback === 'function')
|
|
||||||
this.once('finish', callback);
|
|
||||||
|
|
||||||
if (!this._header) {
|
if (!this._header) {
|
||||||
if (data) {
|
if (data) {
|
||||||
if (typeof data === 'string')
|
if (typeof data === 'string')
|
||||||
@ -581,6 +573,13 @@ OutgoingMessage.prototype.end = function(data, encoding, callback) {
|
|||||||
this.write(data, encoding);
|
this.write(data, encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof callback === 'function')
|
||||||
|
this.once('finish', callback);
|
||||||
|
|
||||||
|
const finish = () => {
|
||||||
|
this.emit('finish');
|
||||||
|
};
|
||||||
|
|
||||||
if (this._hasBody && this.chunkedEncoding) {
|
if (this._hasBody && this.chunkedEncoding) {
|
||||||
ret = this._send('0\r\n' + this._trailer + '\r\n', 'latin1', finish);
|
ret = this._send('0\r\n' + this._trailer + '\r\n', 'latin1', finish);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user