You probably shouldn't use separate operation queues. As these are all cloud file operations, you should have one cloud file operation queues performing all cloud file operations.
If the operations don't depend on other operations, you just add them to this queue and they are performed in any order and as many of them at the same time as the system considers useful. Of course, you can set maxConcurrentOperationCount
to place your own limit on this if you think that is a good idea, but you don't have to, in which case the system will decide for you.
In case operations do depend on each other, you use the operation dependency system. Therefor you first create the operations and then use addDependency
to tell the system which operation depends on which other operation. If you now add all these operations to the queue, the system will make sure to run them in the correct order, so that an operation will only run after all operations it depends on have finished (and these may again depend on other operations and so on). Just make sure to not created cyclic dependencies (OpA depends on OpB which depends on OpC which depends on OpA) as then none of them will ever run.
But to the answer the question in general, in case other users ask how you can simulate a dispatch_sync
with NSOperationQueue
:
NSOperationQueue * queue = ...;
NSOperation * someOperation = [NSBlockOperation
blockOperationWithBlock:^{
// ... do whatever you want to do ...
}
];
[queue addOperation:someOperation];
[someOperation waitUntilFinished];
Note however, that this far less performant than calling dispatch_sync
on a serial dispatch queue since the code above always causes two thread switches whereas calling dispatch_sync
on a serial dispatch queue will reuse the calling thread to run the block and thus no thread switch at all will take place, nor will the process require a second thread to do so. See here for details on how this works.