Skip to content

Commit af0677d

Browse files
committed
Simplify _connectionErrorHandler
1 parent 45e9caf commit af0677d

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

lib/Client.js

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Client.prototype._connect = function() {
5858
var self = this;
5959

6060
socket
61-
.on('error', this._connectionErrorHandler())
61+
.on('error', this._connectionErrorHandler.bind(this))
6262
.on('data', parser.write.bind(parser))
6363
.on('end', this._onEnd.bind(this))
6464
.connect(this.port, this.host);
@@ -238,7 +238,7 @@ Client.prototype._handlePacket = function(packet) {
238238
return;
239239
}
240240

241-
this._connectionErrorHandler()(Client._packetToUserObject(packet));
241+
this._connectionErrorHandler(Client._packetToUserObject(packet));
242242
return;
243243
}
244244

@@ -270,31 +270,29 @@ Client.prototype._handlePacket = function(packet) {
270270
this._dequeue();
271271
};
272272

273-
Client.prototype._connectionErrorHandler = function() {
274-
return function(err) {
275-
this.destroy();
273+
Client.prototype._connectionErrorHandler = function(err) {
274+
this.destroy();
276275

277-
var task = this._queue[0];
278-
var delegate = (task)
279-
? task.delegate
280-
: null;
276+
var task = this._queue[0];
277+
var delegate = (task)
278+
? task.delegate
279+
: null;
281280

282-
if (delegate instanceof Query) {
283-
delegate.emit('error', err);
284-
return;
285-
}
281+
if (delegate instanceof Query) {
282+
delegate.emit('error', err);
283+
return;
284+
}
286285

287-
if (!delegate) {
288-
this.emit('error', err);
289-
} else {
290-
delegate(err);
291-
this._queue.shift();
292-
}
286+
if (!delegate) {
287+
this.emit('error', err);
288+
} else {
289+
delegate(err);
290+
this._queue.shift();
291+
}
293292

294-
if (this._queue.length) {
295-
this._connect();
296-
}
297-
}.bind(this);
293+
if (this._queue.length) {
294+
this._connect();
295+
}
298296
};
299297

300298
Client.prototype._sendAuth = function(greeting) {

0 commit comments

Comments
 (0)