Permalink
Browse files

Fixed major issues with removing listeners after they fire.

  • Loading branch information...
1 parent c309aa5 commit fdceded6abf4a68d7625b92d3e8949557cdec32f Robert Righter committed Feb 16, 2010
Showing with 7 additions and 6 deletions.
  1. +7 −6 lib/longpollingbuffer.js
@@ -1,6 +1,5 @@
// Long Polling Buffer
-// (C) Rob Righter (@robrighter) 2009, Licensed under the MIT-LICENSE
-
+// (C) Rob Righter (@robrighter) 2010, Licensed under the MIT-LICENSE
var sys = require('sys');
//the readbuffer provides a databuffer with a moving offset that can be used to allow AJAX long polling (instead of the websocket)
@@ -19,7 +18,7 @@ function LongPollingBuffer (buffersize) {
while(this.data.length > this.size){
this.data.pop([]);
}
- this.emit('newdata',this.data);
+ this.emit('newData',this.data);
}
this.datasince = function(since) {
@@ -30,9 +29,11 @@ function LongPollingBuffer (buffersize) {
response = this.datasince(since);
if(response.length==0){
//no data yet pass off the callout to wait for it
- this.addListener('newdata', function(thedata){
- callback(this.datasince(since));
- });
+ handler = function(thedata){
+ callback(thedata);
+ this.removeListener('newData', handler);
+ }
+ this.addListener('newData', handler);
}
else {
//send back the data

0 comments on commit fdceded

Please sign in to comment.