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 <cjihrig@gmail.com> Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
This commit is contained in:
parent
fcfd87d7e1
commit
79d2c4e1bf
@ -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
|
// in the future (when a socket gets assigned out of the pool and is
|
||||||
// eventually writable).
|
// eventually writable).
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
function callSocketMethod() {
|
||||||
|
if (method)
|
||||||
|
self.socket[method].apply(self.socket, arguments_);
|
||||||
|
|
||||||
|
if (typeof cb === 'function')
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
|
||||||
var onSocket = function() {
|
var onSocket = function() {
|
||||||
if (self.socket.writable) {
|
if (self.socket.writable) {
|
||||||
if (method) {
|
callSocketMethod();
|
||||||
self.socket[method].apply(self.socket, arguments_);
|
|
||||||
}
|
|
||||||
if (cb) { cb(); }
|
|
||||||
} else {
|
} else {
|
||||||
self.socket.once('connect', function() {
|
self.socket.once('connect', callSocketMethod);
|
||||||
if (method) {
|
|
||||||
self.socket[method].apply(self.socket, arguments_);
|
|
||||||
}
|
|
||||||
if (cb) { cb(); }
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!self.socket) {
|
if (!self.socket) {
|
||||||
self.once('socket', onSocket);
|
self.once('socket', onSocket);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user