Skip to content

Instantly share code, notes, and snippets.

@philstrong
Created September 29, 2011 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philstrong/1251599 to your computer and use it in GitHub Desktop.
Save philstrong/1251599 to your computer and use it in GitHub Desktop.
var pools = {};
var Pool = {
running: false,
jobs: [],
append: function(func) {
var runFunc = function() {
while (jobs.length > 0) {
var job = jobs.shift();
if (job != null) {
job();
}
}
running = false;
};
jobs.push(func);
if (!running) {
running = true;
var fiber = Fiber(runFunc);
fiber.run();
}
}
};
var addJob = function(func, channel) {
channel = channel || '';
if (pools[channel] === undefined) {
pools[channel] = new Pool();
}
pools[channel].append(func);
};
module.exports.addJob = addJob;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment