Created
May 12, 2015 13:38
-
-
Save sanekgusev/2380abd5798f2b5d7d28 to your computer and use it in GitHub Desktop.
dispatch_semaphore + NSBlockOperation
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
- (void)runAsyncOperationWithStartBlock:(void (^)(dispatch_block_t asyncOperationCompletionBlock))startBlock { | |
NSCParameterAssert(startBlock); | |
if (!startBlock) { | |
return; | |
} | |
NSOperation *operation = [NSBlockOperation blockOperationWithBlock:^{ | |
dispatch_semaphore_t completionSemaphore = dispatch_semaphore_create(0); | |
startBlock(^{ | |
dispatch_semaphore_signal(completionSemaphore); | |
}); | |
dispatch_semaphore_wait(completionSemaphore, DISPATCH_TIME_FOREVER); | |
}]; | |
[_operationQueue addOperation:operation]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment