Oh, sorry. I guess your original mention of IResponder as an option ruled out made me think you were using Flex.
In the case of Flash you need to roll your own Async Token pattern.
Here's an article about doing that:
http://corlan.org/2008/08/11/extending-actionscript-classes-to-provide-asynctoken-like-behavior/Following that basic premise, you'd create a custom service component by extending URLLoader, give it an extra property to track your token. For our implementation we'll make a few deviations from that article.
We won't pass the token on the constructor, but make it a simple property. And we won't use data for the property name because that's already a property in the superclass. We'll call it token.
In the Proxy that uses this service, we'll also make sure that the service isn't interrupted by a new load request by returning a Boolean based on whether the token is set. And we'll clear the token after a result is handled.
Your new
ServiceWithToken class:
package me.myapp.model.service
{
public class ServiceWithToken extends URLLoader
{
private var token:Object;
public function ServiceWithToken( )
{
super();
}
}
Back in your
XMLProxy:
public function loadXML( file:String, requestor:String ):Boolean
{
if (service.token == null) return false; // service is being used
var request:URLRequest = new URLRequest(file);
service.load(request); // a ServiceWithToken instance defined in onRegister
var token:Object = new Object();
token.requestor=requestor;
service.token = token;
return true;
}
public function serviceResult( event:ResultEvent ):void // Event.COMPLETE handler set in onRegister
{
var requestingProxy:IProxy = facade.retrieve( service.token.requestor );
requestingProxy.setData( new XML( service.data ) );
service.token=null;
}
So now there's one extra step for you to consider, which is that your proxies that will use the XMLProxy now need to wait if the XMLProxy is being used.
In
SomeRandomXMLNeedingProxy:
public function fetchXML():void // called from a command or mediator once view is prepped
{
var xmlProxy:XMLProxy = facade.retrieveProxy(XMLProxy.NAME);
while ( ! xmlProxy.loadXML('myfile.xml', this.getProxyName() ) {} // brute-force blocking wait
}
The above is one way to handle that. The fetchXML method will simply knock at the door until someone lets it in. That is until the service call that's pending completes, the data is returned to the appropriate proxy and the token is cleared.
-=Cliff>