I have a screen where I make 2 asynchronous calls to get two different pieces of data. What I am trying to do is depending on one set of data, to display or not display a section of the other data.
Is that possible to do since I don’t know which asynchronous task will come back first, and therefore, do not know whether the first piece of data will be available to the system when it tries to determine whether to display the second piece of data?
Is there any reasonable workaround?
Thanks!
well, I believe you are looking for the semaphore pattern.
http://en.wikipedia.org/wiki/Semaphore_(programming)
the idea is this:
have a variable maintaining the number of asynch calls, in your case this is 2. Then, when either call finishes decrement this counter and check the value. If the counter is at 0, you know both calls are done. Remember to reset the counter to 2 if necessary.