Hello, i am writing web application in Flex (SDK 3.5).
my program sends web service calls asynchronically to the server that gives me data.
I want to handle a case when the user sends a few requests before the answers to the previous requests
were answered. In such a case i want to give the UI only the last request answer.
It is similar to web page where the user clicks many times on a button. how to show only the final
answer?
I have an idea for saving the last request id in my proxy/BusinessDelegate class. and then, check the token id to see if it is identical to the last request id. And then i send the data to the UI to display.
What Do you think about this idea? Does anyone have a better idea?
thanks,
views:
29answers:
2
+1
A:
Here's how I handle this kind of situation
private var lastToken:AsyncToken;
public var service:RemoteObject;
public function makeRequest():void
{
lastToken = service.doSomething();
lastToken.addResponder(
new AsyncResponder(handleResult, handleFault, lastToken)
);
}
public function handleResult(result:Object, requestToken:Object):void
{
if(requestToken !== lastToken) return;
else
{
// handle result
}
}
public function handleFault(fault:Object, requestToken:Object):void
{
if(requestToken !== lastToken) return;
else
{
// handle fault
}
}
Ryan Lynch
2010-06-28 19:31:20
A:
I think your idea is the right approach, because that's the way it is! :-)
I do it similarly like in Ryan's in answer and I think you idea has the same direction. The Flex RPC classes use the same approach with the lastResult
property.
splash
2010-06-28 19:45:18