NSURLConnection's +sendAsynchronousRequest and threads
NSURLConnection's +sendAsynchronousRequest and threads
- Subject: NSURLConnection's +sendAsynchronousRequest and threads
- From: Jens Alfke <email@hidden>
- Date: Wed, 14 Dec 2011 15:22:00 -0800
I’d like to use the new +[NSURLConnection sendAsynchronousRequest:…] method in some code I”m writing, as it’s simpler than implementing a custom class with the delegate API, and of course better than running the request synchronously. But the threading model is confusing me.
The method takes an NSOperationQueue on which it’ll run the completion handler block. But the NSOperationQueue docs say that each queue manages a thread pool and will run its operations on its own threads. So that means that my completion block will run on some random background thread, not on the thread that I invoked +sendAsynchronousRequest on. Which is not good.
So how do I get around this? I figured I could at least write an intermediate block to bounce back to the original thread, but was surprised to see that there’s no way to dispatch a block to a specific thread (as far as I can see.) The closest thing is performSelectorOnThread:, but that has the old-style approach of taking a receiver/selector/argument. Isn’t there a way to do this with blocks yet?
—Jens _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden