Skip to content

Commit

Permalink
[fix] don't return the 'connect' emit in case there is a callback and…
Browse files Browse the repository at this point in the history
… ensure the socket is closed before emitting close on the client
  • Loading branch information
jcrugzz committed May 6, 2013
1 parent 7f5ba3a commit a9a6719
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/godot/net/client.js
Expand Up @@ -198,7 +198,7 @@ Client.prototype.connect = function (port, host, callback) {
if (connectBackoff) {
connectBackoff.reset();
}
return self.emit('connect');
self.emit('connect');
});
}

Expand Down Expand Up @@ -227,6 +227,8 @@ Client.prototype.connect = function (port, host, callback) {
// Closes the underlying network connection for this client.
//
Client.prototype.close = function () {
var self = this;

if (this.type === 'tcp' || this.type === 'unix') {
this.socket.destroy();
}
Expand All @@ -240,5 +242,7 @@ Client.prototype.close = function () {
self.remove(self.producers[id]);
});

return this.emit('close');
this.socket.on('close', function () {
self.emit('close');
});
};

0 comments on commit a9a6719

Please sign in to comment.