Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A Library for Node.js that makes comet AJAX long polling simple.

tree: 6698dd4761

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.
latest commit 6698dd4761
Pelle Wessman voxpelli authored robrighter committed
Octocat-spinner-32 lib A push shouldn't lock NodeJS - added nextTick()
Octocat-spinner-32 README.md Removed process.mixin and added Current as a usage example in the doc…
Octocat-spinner-32 example.js removed underscore dependency because v8 has the needed functions bui…
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:

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("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 the buffer)
buffer.addListenerForUpdateSince(-1, function(data){
 sys.puts('\n\nSince forever (or to the size of the buffer): \n' + data.map(JSON.stringify).join(',\n') );
});

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

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

Something went wrong with that request. Please try again.