Skip to content

Commit

Permalink
http: replace finish() callback with arrow function
Browse files Browse the repository at this point in the history
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: #7295
PR-URL: #7378
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Brian White <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
originalfoo authored and jasnell committed Jun 27, 2016
1 parent 926707f commit 3c09d1b
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,14 +546,6 @@ OutgoingMessage.prototype.end = function(data, encoding, callback) {
return false;
}

var self = this;
function finish() {
self.emit('finish');
}

if (typeof callback === 'function')
this.once('finish', callback);

if (!this._header) {
if (data) {
if (typeof data === 'string')
Expand Down Expand Up @@ -581,6 +573,13 @@ OutgoingMessage.prototype.end = function(data, encoding, callback) {
this.write(data, encoding);
}

if (typeof callback === 'function')
this.once('finish', callback);

const finish = () => {
this.emit('finish');
};

if (this._hasBody && this.chunkedEncoding) {
ret = this._send('0\r\n' + this._trailer + '\r\n', 'latin1', finish);
} else {
Expand Down

0 comments on commit 3c09d1b

Please sign in to comment.