如果我有下面定义的方法,传递给该方法的块(“处理程序”)是否会在由创建的新线程上调用NSOperationQueue
?或者它是否在传递给它时所在的线程上被调用methodWithCompletionHandler:
?
-(void)methodWithCompletionHandler:(void (^)(NSString *message))handler
{
// Note: We are currently on thread #1. Calling handler(@"my message") here
// will run on thread #1.
NSBlockOperation* someOp = [NSBlockOperation blockOperationWithBlock: ^{
// do some stuff
}];
[someOp setCompletionBlock:^{
// Note: Now someOp is completing, but it's in thread #2. Does calling the handler
// as below also run in thread #2 or thread #1?
handler(@"Some message.");
}];
NSOperationQueue *queue = [NSOperationQueue new];
[queue addOperation:someOp];
}