"...adding responders after the call has been made..." That is not actually what happens. The call is not made at that line, just set up. I recall reading a fuller explanation, but didn't follow the internals well enough to repeat it.
Tracy ________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Amy Sent: Thursday, December 11, 2008 11:47 AM To: [email protected] Subject: [flexcoders] Re: Best practice for calling asynchronous functions? --- In [email protected] <mailto:flexcoders%40yahoogroups.com> , Mark Carter <[EMAIL PROTECTED]> wrote: > > > Thanks for all the responses. > > I hadn't really looked into the ASyncToken until now. However, for me it > seems that using the ASyncToken would be limited to the implementation of > the, for example, save(XML, Function, Function) method. > > The calling code doesn't need to know about it. Right. The calling code doesn't need to do anything different. The change is inside your method. Here's an example: /* Execute method. If calling object passes in result and fault handlers, those are used. Otherwise, the defaults are used. */ public static function execute(categoryID:int=-1, searchString:String=null, resultHandler:Function=null, faultHandler:Function=null):void{ if (_channels.channels.length==0) { throw new Error('No endpoint specified for GetCategories command Remote Object'); } //set up remote object _ro.channelSet=_channels; _ro.destination = 'AMF_Category'; _ro.source = 'AMF_Category'; //set up a token so we can tell the result of this call from other calls var token:AsyncToken=_ro.getServicesCount (categoryID>-1?categoryID: null, searchString); //assign the result and fault handlers from the calling object token.addResponder(new Responder(! (resultHandler==null)?resultHandler:countLoaded, ! (faultHandler==null)? faultHandler: loadFailed)); } /* trace out the return since we don't know where to put it */ private static function countLoaded (e:ResultEvent):void{ trace(e.result.toString() + ' profiles'); } private static function loadFailed(e:FaultEvent):void{ trace(e.fault); } > In my opinion this is neater > than something like: > > var asyncToken:ASyncToken = save(xml); > asyncToken.addResponder(... Suit yourself. You weren't satisfied with what you were using. I offered an alternative. > Also, I don't like adding responders after the call has been made. I know it > works, but still... Me neither. I'm not sure why they built it this way, but unfortunately that's what we have. Just don't dispatch an event in between LOL. > Maybe I should start a new topic for this next question, but... > > ...in my implementation, I create a new HTTPService for each call. Any ideas > how (in)efficient this is? I'm thinking it's pretty bad. > As you can imagine, it keeps the implementation > much simpler. No need for the ASyncToken. Just add new listeners each time a > call is made. Everything is garbage collected..... Oh, hang on, what keeps a > reference to the HTTPService????? Good question. What did you do with all the old eventListeners you were complaining about in your original post?

