Re: How to get the dispatch queue for the current thread's runloop?
Re: How to get the dispatch queue for the current thread's runloop?
- Subject: Re: How to get the dispatch queue for the current thread's runloop?
- From: Dave Keck <email@hidden>
- Date: Fri, 27 Jan 2012 19:43:03 -0500
Hi Jens,
My understanding is that dispatch queues are tied to threads that are
managed by the system and are separate from run loops. It's therefore
non-sensical to ask for a runloop's queue.
Regardless though, I think a better solution for you is a category on
NSTimer. I use something like the following:
====================
@implementation NSTimer (BlockTimersYay)
+ (NSTimer *)scheduledTimerWithTimeInterval:
(NSTimeInterval)timeInterval repeats: (BOOL)repeats block: (void
(^)(void))block
{
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:
timeInterval target: self selector: @selector(fireBlockTimer:)
userInfo: [[block copy] autorelease] repeats: repeats];
[[NSRunLoop currentRunLoop] addTimer: timer forMode: NSRunLoopCommonModes];
return timer;
}
+ (void)fireBlockTimer: (NSTimer *)blockTimer
{
((void (^)(void))[blockTimer userInfo])();
}
@end
====================
Note that this is slightly different than NSTimer in that the timer is
added to the common modes rather than the default mode.
_______________________________________________
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