Created
February 19, 2011 15:02
-
-
Save mohamedmansour/835107 to your computer and use it in GitHub Desktop.
Asynchronous Function Queue
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 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