var CometIO = function(){
  new EventEmitter().apply(this);
  this.url = "<%= cometio_url %>";
  this.session = null;
  var self = this;

  this.push = function(type, data){
    $.ajax(
      {
        url : self.url,
        data : {type : type, data : data, session : self.session},
        success : function(data){
        },
        error : function(req, stat, e){
          self.emit("error", "CometIO push error");
        },
        complete : function(e){
        },
        type : "POST",
        dataType : "json",
        timeout : 10000
      }
    );
  };

  this.connect = function(){
    self.on("__session_id", function(session){
      self.session = session;
      self.emit("connect", self.session);
    });
    self.get();
    return self;
  };

  this.get = function(){
    $.ajax(
      {
        url : self.url,
        data : {session : self.session},
        success : function(data){
          if(data){
            self.emit(data.type, data.data);
          }
          self.get();
        },
        error : function(req, stat, e){
          self.emit("error", "CometIO get error");
          setTimeout(self.get, 10000);
        },
        complete : function(e){
        },
        type : "GET",
        dataType : "json",
        timeout : 60000
      }
    );
  };
};

@@ -111,16 +111,39 @@
 = null;%0A
+  var running = false;%0A
   var se
@@ -612,24 +612,53 @@
 function()%7B%0A
+    if(running) return self;%0A
     self.on(
@@ -692,16 +692,16 @@
 ssion)%7B%0A
-
       se
@@ -772,16 +772,36 @@
     %7D);%0A
+    running = true;%0A
     self
@@ -842,25 +842,145 @@
 his.
-get = function()%7B
+close = function()%7B%0A    running = false;%0A    self.removeListener(%22__session_id%22);%0A  %7D;%0A%0A  this.get = function()%7B%0A    if(!running) return;
 %0A   

add function CometIO.close()