Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'll try one more idea:</p> <p>Have your Data Access Object return their own AsyncTokens (or some other objects that encapsulate a pending call), instead of the AsyncToken that comes from the RPC call. So, in the DAO it would look something like this (this is very sketchy code):</p> <pre><code>public function deleteThing( id : String ) : DeferredResponse { var deferredResponse : DeferredResponse = new DeferredResponse(); var asyncToken : AsyncToken = theRemoteObject.deleteThing(id); var result : Function = function( o : Object ) : void { deferredResponse.notifyResultListeners(o); } var fault : Function = function( o : Object ) : void { deferredResponse.notifyFaultListeners(o); } asyncToken.addResponder(new ClosureResponder(result, fault)); return localAsyncToken; } </code></pre> <p>The <code>DeferredResponse</code> and <code>ClosureResponder</code> classes don't exist, of course. Instead of inventing your own you could use <code>AsyncToken</code> instead of <code>DeferredResponse</code>, but the public version of <code>AsyncToken</code> doesn't seem to have any way of triggering the responders, so you would probably have to subclass it anyway. <code>ClosureResponder</code> is just an implementation of <code>IResponder</code> that can call a function on success or failure.</p> <p>Anyway, the way the code above does it's business is that it calls an RPC service, creates an object encapsulating the pending call, returns that object, and then when the RPC returns, one of the closures <code>result</code> or <code>fault</code> gets called, and since they still have references to the scope as it was when the RPC call was made, they can trigger the methods on the pending call/deferred response.</p> <p>In the command it would look something like this:</p> <pre><code>public function execute( ) : void { var deferredResponse : DeferredResponse = dao.deleteThing("3"); deferredResponse.addEventListener(ResultEvent.RESULT, onResult); deferredResponse.addEventListener(FaultEvent.FAULT, onFault); } </code></pre> <p>or, you could repeat the pattern, having the <code>execute</code> method return a deferred response of its own that would get triggered when the deferred response that the command gets from the DAO is triggered.</p> <p>But. I don't think this is particularly pretty. You could probably do something nicer, less complex and less entangled by using one of the many application frameworks that exist to solve more or less exactly this kind of problem. My suggestion would be <a href="http://mate.asfusion.com" rel="nofollow noreferrer">Mate</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload