Last active
August 29, 2015 14:23
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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