Skip to content

Instantly share code, notes, and snippets.

@philstrong
Created September 29, 2011 19:31
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/1251690 to your computer and use it in GitHub Desktop.
Save philstrong/1251690 to your computer and use it in GitHub Desktop.
Ext.define('ficus.fiber.Manager', {
requires: ['ficus.fibers.Pool'],
singleton: true,
pools: {},
addJob: function(func, channel) {
var me = this,
pools = me.pools;
channel = channel || '';
if (pools[channel] === undefined) {
pools[channel] = Ext.create('ficus.fiber.Pool');
}
pools[channel].append(func);
}
});
Ext.define('ficus.fiber.Pool', {
running: false,
jobs: [],
append: function(func) {
var runFunc = function() {
var job;
while (jobs.length > 0) {
job = jobs.shift();
if (job != null) {
job();
}
}
running = false;
};
jobs.push(func);
if (!running) {
running = true;
var fiber = Fiber(runFunc);
fiber.run();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment