Skip to content

Instantly share code, notes, and snippets.

@Sega-Zero
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sega-Zero/ac0b1dc5fa093939938c to your computer and use it in GitHub Desktop.
Save Sega-Zero/ac0b1dc5fa093939938c to your computer and use it in GitHub Desktop.
an example of NSOperation addDependency for this SO question: http://stackoverflow.com/q/30851799/1254172
//assume NSOperationQueue *operationQueue is created somewhere
//assume dispatch_semaphore_t semaphore is created somewhere
NSOperation *firstOperation = [NSBlockOperation blockOperationWithBlock:^{
[self doTask1];
}];
NSOperation *secondOperation = [NSBlockOperation blockOperationWithBlock:^{
[self doTask2];
}];
NSOperation *notificationOperation = [NSBlockOperation blockOperationWithBlock:^{
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
}];
NSOperation *completionOperation = [NSBlockOperation blockOperationWithBlock:^{
[self completionTask];
}];
[completionOperation addDependency:firstOperation];
[completionOperation addDependency:secondOperation];
[completionOperation addDependency:notificationOperation];
[operationQueue addOperations:@[firstOperation, secondOperation, notificationOperation, completionOperation] waitUntilFinished:NO];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment