How to tell if there's an active runloop?
How to tell if there's an active runloop?
- Subject: How to tell if there's an active runloop?
- From: Jens Alfke <email@hidden>
- Date: Wed, 26 Mar 2014 14:33:37 -0700
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 (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