The initialization code for our Flex application runs a series of asynchronous calls to verify user credentials, load external data, connect to a JMS theme, etc. Depending on the context in which the application is running, some of these calls are not made or are made with different parameters.
Because all of these calls occur asynchronously, the code that manages them is difficult to read, understand, maintain, and test. For each call, we need to have some callback mechanism in which we decide which call to make next.
I was wondering if anyone had experimented with wrapping these calls in executable modules and had a Fluent Interface (FI) that could connect and manage them.
From the top of my head, the code might look something like this:
var asyncChain:AsyncChain = execute(LoadSystemSettings) .execute(LoadAppContext) .if(IsAutologin) .execute(AutoLogin) .else() .execute(ShowLoginScreen) .etc; asyncChain.execute();
AsyncChain will be the execution tree, we will build using FI (and we could, of course, also build one without FI).
This might be an interesting idea for environments that work in the same stream model, such as Flash Player, Silverlight, JavaFX?, ...
Before diving into the code to try everything, I was hoping to get some feedback.
Update 03/19/2010 . We created an experimental Task API in a Spring ActionScript project that provides control over async processes. We will be happy to receive feedback. http://www.springactionscript.org/docs/reference/html/the_operation_api.html#tasks