On 27 April 2016 at 17:49, Greg Keogh <gfke...@gmail.com> wrote: > If you are not waiting for the tasks to finish, won't you run into a race >> condition? >> > > The backend in my actual case is reading a web service, which can be > hammered by overlapping calls. All of the callbacks will run on the UI > thread, so they can't step on each other. I hope I'm right?! -- *Greg* >
Sounds right, as long as UpdateUI can run at any time, in any order. You might also need to deal with the situation where two async tasks are running concurrently for the same "operation", e.g. hitting refresh a second time before the first completes. One way to avoid this is to disable refresh while a refresh is already in progress, but that can be limiting/annoying for the user. Instead, I normally defer updating the UI until the latest request completes. That way it doesn't flicker with stale responses before settling down, and you are guaranteed to leave the form showing the result for the latest request. Note that since they are running concurrently, some stale responses may also come in after the one you were waiting for. These should be discarded as well. -- Thomas