Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e7b8400

Browse filesBrowse 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 <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>
1 parent 44bc638 commit e7b8400
Copy full SHA for e7b8400

File tree

Expand file treeCollapse file tree

1 file changed

+7
-8
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+7
-8
lines changed
Open diff view settings
Collapse file

‎lib/_http_outgoing.js‎

Copy file name to clipboardExpand all lines: lib/_http_outgoing.js
+7-8Lines changed: 7 additions & 8 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.