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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to