So in Flex you can invoke a service (like a WebService method, or HTTPService.send()), which returns a token (mx.rpc.AsyncToken). After that, you set a responder on the token. When the results come back, the responder is called. Calling the send() method actually sends the request, so the whole construct looks bizarre, since you’re setting a responder/handler AFTER the call has been sent. This is a very common pattern in Cairngorm applications.
The fact is that this never fails, and I wondered why, because it looks possible (although unlikely) for an RPC call to return data before the responder is set. After thinking for a while, I remembered one of my first problems with Flash, years ago: it’s single threaded. After investigating on the web, I found out this is really what makes this (and a whole host of other async stuff) work in Flash/Flex. The call may return data, but since it’s single threaded, your method will surely be able to continue, and set the responder, before the result handler is called. Uncommon, to say the least.
It has long been looking for this information, Thank you for your work.
I have actually been puzzled with this myself for quite some time. I am actually still today unclear on how can flex be asynchronous and single threaded??
The call to send() only prepares the call to the actual server, some event scheduler of some sort and returns the async token which I can set w/ the responder?
I am sure that’s not the way it works….it just sounds lame…
Can you please re-explain this? Thank you.