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 f68fed2

Browse filesBrowse files
ahoymrvagg
authored andcommitted
http: remove redundant code in _deferToConnect
Logic for calling the passed in socket method and/or callback was duplicated. This commit refactors the relevant code to remove the redundancy. PR-URL: #2769 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
1 parent cb971cc commit f68fed2
Copy full SHA for f68fed2

File tree

Expand file treeCollapse file tree

1 file changed

+12
-10
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-10
lines changed
Open diff view settings
Collapse file

‎lib/_http_client.js‎

Copy file name to clipboardExpand all lines: lib/_http_client.js
+12-10Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -504,21 +504,23 @@ ClientRequest.prototype._deferToConnect = function(method, arguments_, cb) {
504504
// in the future (when a socket gets assigned out of the pool and is
505505
// eventually writable).
506506
var self = this;
507+
508+
function callSocketMethod() {
509+
if (method)
510+
self.socket[method].apply(self.socket, arguments_);
511+
512+
if (typeof cb === 'function')
513+
cb();
514+
}
515+
507516
var onSocket = function() {
508517
if (self.socket.writable) {
509-
if (method) {
510-
self.socket[method].apply(self.socket, arguments_);
511-
}
512-
if (cb) { cb(); }
518+
callSocketMethod();
513519
} else {
514-
self.socket.once('connect', function() {
515-
if (method) {
516-
self.socket[method].apply(self.socket, arguments_);
517-
}
518-
if (cb) { cb(); }
519-
});
520+
self.socket.once('connect', callSocketMethod);
520521
}
521522
};
523+
522524
if (!self.socket) {
523525
self.once('socket', onSocket);
524526
} else {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.