The initialization code of our Flex application is doing a series of asynchronous calls to check user credentials, load external data, connecting to a JMS topic, etc. Depending on the context the application runs in, some of these calls are not executed or executed with different parameters.
Since all of these calls happen asynchronously, the code controlling them is hard to read, understand, maintain and test. For each call, we need to have some callback mechanism in which we decide what call to execute next.
I was wondering if anyone had experimented with wrapping these calls in executable units and having a Fluent Interface (FI) that would connect and control them.
From the top of my head, the code might look something like:
var asyncChain:AsyncChain = execute(LoadSystemSettings)
.execute(LoadAppContext)
.if(IsAutologin)
.execute(AutoLogin)
.else()
.execute(ShowLoginScreen)
.etc;
asyncChain.execute();
The AsyncChain would be an execution tree, build with the FI (and we could of course also build one without a FI).
This might be an interesting idea for environments that run in a single threaded model like the Flash Player, Silverlight, JavaFX?, ...
Before I dive into the code to try things out, I was hoping to get some feedback.