Re: My runloop-based async code breaks with GCD
Re: My runloop-based async code breaks with GCD
- Subject: Re: My runloop-based async code breaks with GCD
- From: Dave Keck <email@hidden>
- Date: Sat, 18 Feb 2012 01:24:00 -0500
The root of your problem seems to be your assumption that GCD runs the run loop.
NSURLConnection case: the delegate methods aren't called because
NSURLConnection machinery requires the run loop to be run, which GCD
isn't going to do for you. (Calling -setDelegateQueue: fixes this
because NSURLConnection presumably has a secondary operating manner
that uses an NSOperationQueue instead of a run loop).
Perform selector case: likewise, this doesn't work when called from a
queue because GCD isn't going to handle running the run loop for you.
The run loop is run by something calling CFRunLoopRunInMode(). On the
main thread, this is typically handled for you by AppKit (specifically
by NSApplication's -nextEventMatchingMask:). On secondary threads, you
must manually invoke CFRunLoopRunInMode() to allow anything relying on
the run loop to work correctly. (NSURLConnection uses run loop sources
to work in the non-NSOperationQueue case, and -performSelector uses a
timer.)
In short, dispatch queues are a lower-level abstraction to the run
loop, and won't run the run loop for you.
_______________________________________________
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