Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A Library for Node.js that makes comet AJAX long polling simple.
JavaScript
tree: 6ab3e5a214

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
README.md
example.js

README.md

Long Polling Buffer

(C) Rob Righter (@robrighter) 2009, Licensed under the MIT-LICENSE

A Library for Node.js to simplify AJAX long polling

API

LongPollingBuffer(buffersize)

Constructor. Initializes the buffer to be of size buffersize

push(value)

Pushes data onto the queue which in turn notifies all the listeners

addListenerForUpdateSince(since, callback)

Adds a listener for data updates. The callback is triggered when data is available after the since.

Example usage: Simple Activity Monitor

var sys = require('sys');
var un = require("./lib/underscore");
var lpb = require("./lib/longpollingbuffer");

var buffer = new lpb.LongPollingBuffer(8);

buffer.push("I'm");
buffer.push('affraid');
buffer.push('the Death Star');
buffer.push('will be');
buffer.push('fully');
buffer.push('operational');
buffer.push('when');
buffer.push('your');
buffer.push('friends');
buffer.push('arrive');


//Since forever (or to the size of teh buffer)
buffer.addListenerForUpdateSince(-1, function(data){
 sys.puts('\n\nSince forever (or to the size of the buffer): \n' + _.map(data,JSON.stringify).join(',\n') );
});

//Since offset 6
buffer.addListenerForUpdateSince(6, function(data){
 sys.puts('\n\nSince offset 6: \n' + _.map(data,JSON.stringify).join(',\n') );
});

To see an example of LongPollingBuffer used in a webapp here.

Something went wrong with that request. Please try again.