Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.