Skip to content

Commit e7b8400

Browse files
originalfooFishrock123
authored andcommitted
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: #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]>
1 parent 44bc638 commit e7b8400

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lib/_http_outgoing.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -546,14 +546,6 @@ OutgoingMessage.prototype.end = function(data, encoding, callback) {
546546
return false;
547547
}
548548

549-
var self = this;
550-
function finish() {
551-
self.emit('finish');
552-
}
553-
554-
if (typeof callback === 'function')
555-
this.once('finish', callback);
556-
557549
if (!this._header) {
558550
if (data) {
559551
if (typeof data === 'string')
@@ -581,6 +573,13 @@ OutgoingMessage.prototype.end = function(data, encoding, callback) {
581573
this.write(data, encoding);
582574
}
583575

576+
if (typeof callback === 'function')
577+
this.once('finish', callback);
578+
579+
const finish = () => {
580+
this.emit('finish');
581+
};
582+
584583
if (this._hasBody && this.chunkedEncoding) {
585584
ret = this._send('0\r\n' + this._trailer + '\r\n', 'binary', finish);
586585
} else {

0 commit comments

Comments
 (0)