From: Malcolm Ahoy Date: Wed, 9 Sep 2015 13:11:19 +0000 (-0700) Subject: http: remove redundant code in _deferToConnect X-Git-Tag: v4.1.1~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f68fed2e6ff008cd0464831d4b1f081be1f65efc;p=platform%2Fupstream%2Fnodejs.git 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: https://github.com/nodejs/node/pull/2769 Reviewed-By: Colin Ihrig Reviewed-By: Brendan Ashworth --- diff --git a/lib/_http_client.js b/lib/_http_client.js index e490dce..8ddf334 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -504,21 +504,23 @@ ClientRequest.prototype._deferToConnect = function(method, arguments_, cb) { // in the future (when a socket gets assigned out of the pool and is // eventually writable). var self = this; + + function callSocketMethod() { + if (method) + self.socket[method].apply(self.socket, arguments_); + + if (typeof cb === 'function') + cb(); + } + var onSocket = function() { if (self.socket.writable) { - if (method) { - self.socket[method].apply(self.socket, arguments_); - } - if (cb) { cb(); } + callSocketMethod(); } else { - self.socket.once('connect', function() { - if (method) { - self.socket[method].apply(self.socket, arguments_); - } - if (cb) { cb(); } - }); + self.socket.once('connect', callSocketMethod); } }; + if (!self.socket) { self.once('socket', onSocket); } else {