I want to execute an NSOperation synchronously on the currently executing thread. Can I just call [NSOperation start]? Does this always run in the currently executing thread?
An alternative is to just create an NSOperationQueue, add the operation then call waitUntilAllOperationsFinished selector.
If you call
[NSOperation start], it will execute synchronously on the current thread. All the asynchronous work surrounding operations is handled byNSOperationQueue, but if you’re calling-startyourself then you’re bypassing all of that.Of course, a particular
NSOperationsubclass may be implemented to spawn off an asynchronous task itself on another thread; that’s entirely up to it. But an operation that’s designed to execute synchronously in whatever thread the operation queue runs it in, will also execute synchronously in your thread if you call-start.For example, the following code, when run:
prints: