2

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!!

JD Isaacks
  • 56,088
  • 93
  • 276
  • 422

3 Answers3

6

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)
}
Eric Kolb
  • 996
  • 6
  • 9
5

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

More info here: HTTPService#concurrency

Robert Bak
  • 4,246
  • 19
  • 20
  • Hi All, How stop the execution of HTTP Service when when it is in the middle?. My Scenario; I make a Search Service that is search patient from DB from a front end Text Input. If user change the text that he/she enter before i send the service call again but i want result on base of last entered text, the first one call that i send() i want to destroy or stop it. How i achieve this? Thanks in Advance. – Tahir Alvi Oct 31 '11 at 10:09
  • See: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/rpc/http/HTTPService.html#cancel() – Robert Bak Oct 31 '11 at 15:07
1

In addition to Robert's answer: Flex: Cancel HTTPService.send()?

HTTPService#concurrency seems to be introduced until Flex 4, I don't find this in Flex 3.. In Flex 3., you have to cancel the previous call manually in contrast to concurrency="last" in Flex 4.

Note that this won't interrupt server process that previous call invokes, it means server may still come out a response however flex abandon that already.

Community
  • 1
  • 1
Evi Song
  • 862
  • 11
  • 14