Created
September 29, 2011 19:31
-
-
Save philstrong/1251690 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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