Skip to content

Commit d8e3ccc

Browse files
committed
Cleaned up the code, changed tabs to spaces and incorporated feedback on from the pull request
1 parent cef5fb3 commit d8e3ccc

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

lib/socket.io/client.js

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,39 +67,32 @@ Client.prototype._onConnect = function(req, res){
6767
this.request = req;
6868
this.response = res;
6969
this.connection = req.connection;
70-
71-
if(!attachConnection) attachConnection = !attachConnection && this.connection.eventsAttached === undefined;
72-
this.connection.eventsAttached = true;
70+
71+
if(!attachConnection) attachConnection = !attachConnection && this.connection.eventsAttached === undefined;
72+
this.connection.eventsAttached = true;
7373

7474
if (attachConnection){
75-
this.connection.addListener('end', function(){
76-
self._onClose();
77-
self.connection && self.connection.destroy()
78-
});
79-
this.connection.addListener('timeout', function(){
75+
function destroyConnection(){
8076
self._onClose();
8177
self.connection && self.connection.destroy()
82-
});
83-
this.connection.addListener('error', function(){
84-
self._onClose();
85-
self.connection && self.connection.destroy()
86-
});
78+
};
79+
this.connection.addListener('end', destroyConnection);
80+
this.connection.addListener('timeout', destroyConnection);
81+
this.connection.addListener('error', destroyConnection);
8782
}
8883

8984
if (req){
90-
req.addListener('error', function(err){
91-
req.destroy && req.destroy();
92-
});
93-
req.addListener('timeout', function(err){
85+
function destroyRequest(){
9486
req.destroy && req.destroy();
95-
});
87+
};
88+
req.addListener('error', destroyRequest);
89+
req.addListener('timeout', destroyRequest);
9690
if (res){
97-
res.addListener('error', function(err){
98-
res.destroy && res.destroy();
99-
});
100-
res.addListener('timeout', function(err){
91+
function destroyResponse(){
10192
res.destroy && res.destroy();
102-
});
93+
}
94+
res.addListener('error', destroyResponse);
95+
res.addListener('timeout', destroyResponse);
10396
}
10497
if (this._disconnectTimeout) clearTimeout(this._disconnectTimeout);
10598
}

0 commit comments

Comments
 (0)