Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex: Cancel HTTPService.send()?

OK I have an HTTPService that executes the dataLoaded(e:ResultEvent):void function whenever it gets a result from a send() call.

OK so If I call HTTPService.send() and then call HTTPService.send() again before the previous one receives a result, I end up repeatedly running dataLoaded() which is undesirable

What I want is if HTTPService.send() gets called before a previous call to it returns a result. I want to cancel the first call, and only process the result from the last call to HTTPService.send()

I hope this makes sense.

How can I do that??

Thanks!!

like image 890
JD Isaacks Avatar asked Feb 01 '26 00:02

JD Isaacks


2 Answers

HTTPService has a cancel method. If you call it without its parameter, it should cancel the last invocation of the service. Give that a try and see if you're still getting undesired ResultEvents.

Use the existence of the ASyncToken to determine whether cancellation is appropriate.

private var _serviceCall:ASyncToken;

function callMyService(stuff:Object):void {
    if (_serviceCall !== null) {
        myService.cancel();
        _serviceCall = null;
    }
    _serviceCall = myService.send(stuff)
}
like image 72
Eric Kolb Avatar answered Feb 03 '26 01:02

Eric Kolb


Actually HTTPService can manage this for you. It has a concurrency property, which you should probably set to "last".

More info here: HTTPService#concurrency

like image 33
Robert Bak Avatar answered Feb 03 '26 01:02

Robert Bak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!