Skip to content
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

Http: Improve finish() callback and code legibility (Fixes #7295) #7378

Closed
wants to merge 4 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);

var finish = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if better if in places like this you use const instead var

Copy link
Contributor Author

@originalfoo originalfoo Jun 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, will update PR shortly.

EDIT: Done.

this.emit('finish');
};

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