Re: How to tell if there's an active runloop?
Re: How to tell if there's an active runloop?
- Subject: Re: How to tell if there's an active runloop?
- From: Ken Thomases <email@hidden>
- Date: Wed, 26 Mar 2014 17:23:15 -0500
On Mar 26, 2014, at 4:48 PM, Kyle Sluder wrote:
> On Wed, Mar 26, 2014, at 02:33 PM, Jens Alfke wrote:
>> I’d like to be able to detect this situation and log a warning or throw
>> an exception. But I can’t figure out what to check. I know that
>> [NSRunLoop currentRunLoop] will create a new runloop for the current
>> thread if one doesn’t exist, so it never returns nil. Will looking at its
>> -currentMode help? Or should I bridge over to CFRunLoop and check whether
>> there are any attached sources?
>
> This smells like a really bad design.
>
> The concept of an "active" runloop doesn't actually map to anything that
> accurately describes the system. Some code might use
> -runMode:beforeDate: to process a single event at a time. That code
> might be invoked by code that's running a runloop via -run. And the
> runloop might _never_ run in the mode in which you post your
> -performSelector:afterDelay:.
I agree. Even if the runloop is currently being run in the mode you want or you could detect that it had been at some point, there's no guarantee that it will again. There's also the potential for false negatives if the code calls into your library before doing anything runloop-related but would subsequently run its runloop in a way that would work for your library.
As you're aware, there are plenty of Apple APIs that require that the client run the runloop of the calling thread or notifications don't come through. Your library has a similar requirement, whether it was explicitly documented before or not. Developers need to understand this and be prepared to code accordingly, assuming you clearly document it. In other words, I don't think this has a technical solution.
Regards,
Ken
_______________________________________________
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