IrcConnection.prototype.dispose = function () {
var that = this;
+ // If we're still connected, wait until the socket is closed before disposing
+ // so that all the events are still correctly triggered
+ if (this.socket && this.connected) {
+ this.socket.end();
+ return;
+ }
+
+ if (this.socket) {
+ this.disposeSocket();
+ this.removeAllListeners();
+ }
+
_.each(this.irc_users, function (user) {
user.dispose();
});
this.server.dispose();
this.server = undefined;
- EventBinder.unbindIrcEvents('', this.irc_events, this);
+ this.irc_commands = undefined;
- // If we're still connected, wait until the socket is closed before disposing
- // so that all the events are still correctly triggered
- if (this.socket && this.connected) {
- this.socket.once('close', function() {
- that.disposeSocket();
- that.removeAllListeners();
- });
-
- this.socket.end();
+ EventBinder.unbindIrcEvents('', this.irc_events, this);
- } else {
- this.disposeSocket();
- this.removeAllListeners();
- }
};
_.each(that.irc_connections, function (irc_connection, i, cons) {
if (irc_connection) {
irc_connection.end('QUIT :' + (global.config.quit_message || ''));
- irc_connection.dispose();
global.servers.removeConnection(irc_connection);
cons[i] = null;
}