Re: waiting for async callback in main thread
Re: waiting for async callback in main thread
- Subject: Re: waiting for async callback in main thread
- From: Kyle Sluder <email@hidden>
- Date: Tue, 27 Oct 2009 21:21:38 -0700
On Tue, Oct 27, 2009 at 8:53 PM, John Engelhart
<email@hidden> wrote:
> I would *STRONGLY* advise against doing this. While it may be perfectly safe
> to recursively run a CFRunLoop, this says nothing about the implications of
> doing so. At first glance, it would seem that everything a run loop "does"
> as a result of 'running' needs to be safe to call recursively as well. This
> condition is much harder to satisfy, and virtually guaranteed not hold true
> for code that gets executed by the main threads run loop.
Cocoa apps re-enter their run loops all the time. Mouse tracking
would be an excellent example, but also turning asynchronous
operations into synchronous ones, just like the OP described. (I was
going to mention Distributed Objects, but perhaps that would not be a
shining example.)
The key is to use a custom run loop mode. Schedule your observation
only in the MyWaitingForResponseRunLoop mode, and only run that mode
in your while loop. Reentrancy issue solved.
--Kyle Sluder
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden