Are Objective-C blocks always executed in a separate thread?
Specifically, I’m asking about the sendAsynchronousRequest:queue:completionHandler method of the NSURLConnection class. This is the scenario:
Main thread (1st thread) calls the sendAsynchronousRequest method the
sendAsynchronousRequest is executed on a 2nd thread, managed by the
NSOperationQueue when method is completed and calls
commpletionHandler, which thread is it executed on? 2nd thread? yet
another 3rd thread? or the 1st thread?
Thanks!
It executes it on whatever operation queue you specify as the
queueargument:The
queueparameter is documented as:So it’s really up to the
NSOperationQueueexactly how many threads are used. I’d expect pooling behaviour – so while there can be multiple threads, I wouldn’t expect a different thread per handler, necessarily.