Server: re-arranged disposing
authorDarren <darren@darrenwhitlen.com>
Mon, 29 Oct 2012 20:20:39 +0000 (20:20 +0000)
committerDarren <darren@darrenwhitlen.com>
Mon, 29 Oct 2012 20:20:39 +0000 (20:20 +0000)
Websocket event handlers should not have to worry about emiting
'destory' event, that is the disposings job

server/client.js

index 1dc47e25189a929f0cf049afc2d2dea1faed30f2..666384cb521e6079f72f8396a24f77d2432690c5 100755 (executable)
@@ -65,7 +65,7 @@ Client.prototype.sendKiwiCommand = function (command, data, callback) {
 };
 
 Client.prototype.dispose = function () {
-    websocketDisconnect.apply(this);
+    this.emit('destroy');
     this.removeAllListeners();
 };
 
@@ -152,12 +152,12 @@ function websocketDisconnect() {
             cons[i] = null;
         }
     });
-    this.emit('destroy');
+    
+    this.dispose();
 }
 
 
 // TODO: Should this close all the websocket connections too?
 function websocketError() {
-    this.emit('destroy');
     this.dispose();
 }
\ No newline at end of file