Skip to content

Instantly share code, notes, and snippets.

@mohamedmansour
Created February 19, 2011 15:02
Show Gist options
  • Save mohamedmansour/835107 to your computer and use it in GitHub Desktop.
Save mohamedmansour/835107 to your computer and use it in GitHub Desktop.
Asynchronous Function Queue
var function_queue = [
funcA,
funcB,
funcC,
funcD
];
function doNextAction() {
if (function_queue.length) {
var next_function_call = function_queue.shift();
next_function_call();
}
}
function doProcess() {
// do something.
doNextAction();
}
function funcA() {
doNextAction();
}
function funcB() {
if (value is not null) {
doNextAction();
return;
}
// Result is null do something else.
function_queue.unshift(funcD);
}
function funcC() {
doNextAction();
}
function funcD() {
// Done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment