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: Kyle Sluder <email@hidden>
- Date: Wed, 26 Mar 2014 14:48:15 -0700
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:.
If you want to delay something for later, you should probably use
dispatch_after.
--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