Created
January 11, 2011 21:52
-
-
Save buzzedword/775230 to your computer and use it in GitHub Desktop.
Simple async building blocks for threading
This file contains 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
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