Skip to content
A Library for Node.js that makes comet AJAX long polling simple.
Find file
Latest commit 6698dd4 Aug 3, 2010 @voxpelli voxpelli committed with A push shouldn't lock NodeJS - added nextTick()
A pollbuffer with very many or heavy listeners can keep NodeJS quite busy on a push - especially if many pushes are made at once.

By putting the notification of all listeners on nextTick() we avoid that multiple pushes always results in multiple notifications. If a notification is already due to happen it will wait for that.

By putting each individual notification on nextTick() we ensure that very many listeners or a few heavy ones wont lock NodeJS for too long.

Long Polling Buffer

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

A Library for Node.js to simplify AJAX long polling



Constructor. Initializes the buffer to be of size buffersize


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:

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

var buffer = new lpb.LongPollingBuffer(8); //create a buffer with a size of 8

buffer.push('the Death Star');
buffer.push('will be');

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

//Since offset 6
buffer.addListenerForUpdateSince(6, function(data){
 sys.puts('\n\nSince offset 6: \n' +',\n') );

You can also see an example of LongPollingBuffer used in a webapp here.

Something went wrong with that request. Please try again.