Problem 1: How can I make sure multiple asynch remote method calls do
not end up canceling each other?

Consider this pseudo code:

onButtonClick()
{
  doStuff();
  requestSoapData.addEventListener(..., handleSoapResult);
  requestSoapData.send();
}

handleSoapResult()
{
  doMoreStuff();
  requestSoapData.removeEventListener(..., handleSoapResult); 
  // remove handler so this handler doesn't get called again when some
other control fires requestSoapData.
}

I add the listener before the call and remove after processing the
result, so that there will be no side-effect if another function calls
the same remote method. This was a pattern suggested to me previously
which I find is better than registering listeners permanently.

Now the problem is that since remote calls are asynchronous in nature,
how can I prevent the first result from coming back and removing the
listener BEFORE the second (or any subsequent) calls from invoking the
correct listener? Or am I somehow guaranteed that listeners will not
be removed until a pending remote call returns?

If this is not the correct pattern, then can anyone suggest a better
way of making sure each call to the *same* remote method invokes the
correct listener upon return w/o any side-effects from each other?

The single threaded nature of Flash Player that forces the asynch I/O
pattern leads me to my 2nd problem.

Problem 2: Is there an easy way to synchronize a string of network
calls at all?

I'm attempting to write a test script to test both my Flash frontend
and server backend. However, in order to run a series of tests, I need
to wait for the result from each previous remote call to come back
before invoking the next one.

One proven, but tedious way, is to have a string of listeners that
registers the next listener, then kicks off the next remote call. But
this just doesn't seem like good programming. The ugliness is next to
using nested if statements where a switch would do.

Can anyone suggest a better way of synchronizing remote calls for
testing purposes? Or is this just impossible due to Flash architecture?

Thanks!

Reply via email to