// 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 {