Amy-28 wrote:
>
> Right. The calling code doesn't need to do anything different. The
> change is inside your method.
>
> Here's an example:
>
Thanks for that - its roughly what I had in mind - but its good for me to
see an example.
Amy-28 wrote:
>
>> 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.
>
Maybe I wasn't being clear. I just prefer to keep any ASyncToken code out of
the calling code. Having it inside the implementation is not a problem for
me (other than for the other problems with it discussed in this topic). So,
I don't see it as an alternative - its more of an implementation detail.
Amy-28 wrote:
>
>> 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?
>
My current implementation has something like:
function save(xml:XML, successFunc:Function, failureFunc:Function):void {
var service:HTTPService = new HTTPService();
...
service.addEventListener(ResultEvent.RESULT,
function(evt:ResultEvent):void {
trace("Successfully saved XML");
successFunc();
});
service.send(); // called after the event listeners have been added :)
}
That's it. The successFunc and failureFunc are only scoped to the calling
code's method and so should be garbage collected when the service is garbage
collected.
What I don't know is when the service is garbage collected? I'm assuming not
before the result or fault event is fired!
--
View this message in context:
http://www.nabble.com/Best-practice-for-calling-asynchronous-functions--tp20930596p20969533.html
Sent from the FlexCoders mailing list archive at Nabble.com.