Skip to content

Instantly share code, notes, and snippets.

@buzzedword
Created January 11, 2011 21:52
Show Gist options
  • Save buzzedword/775230 to your computer and use it in GitHub Desktop.
Save buzzedword/775230 to your computer and use it in GitHub Desktop.
Simple async building blocks for threading
var queueExecutionInterval = 200,
debug = function (call) {
if ("console" in window) {
console.log.apply(call);
}
},
QUEUE = [],
SECONDARY = [],
functionContainer, primaryThread = setInterval(function () { // QUEUE.push( function ) to register item for queue processing.
if (QUEUE.length > 1) {
functionContainer = QUEUE.shift();
functionContainer;
debug('primary execution item');
}
}, queueExecutionInterval),
secondaryThread = setInterval(function () { // QUEUE.push( function ) to register item for queue processing.
if (SECONDARY.length > 1) {
functionContainer = SECONDARY.shift();
functionContainer;
debug('secondary execution item');
}
}, (queueExecutionInterval + (queueExecutionInterval / 2))),
hyperThread = function (call) {
var mode = Math.round(Math.random());
((mode === 0) ? QUEUE.push(call) : ((mode == 1) ? SECONDARY.push(call) : null));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment