Is there a way to tell whether the current thread has an active runloop?

I ask because the library that I develop will internally call 
-performSelector:withObject:afterDelay to schedule an action at a later time. 
The library can be used on a background thread, with some caveats. A couple of 
times recently I’ve gotten bug reports where the developer says they never get 
notifications that the library should be posting; the problem turns out to be 
that their background thread isn’t running a runloop, so my delayed-performs 
never trigger.

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?

—Jens
_______________________________________________

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