Skip to content

Instantly share code, notes, and snippets.

@sanekgusev
Created May 12, 2015 13:38
Show Gist options
  • Save sanekgusev/2380abd5798f2b5d7d28 to your computer and use it in GitHub Desktop.
Save sanekgusev/2380abd5798f2b5d7d28 to your computer and use it in GitHub Desktop.
dispatch_semaphore + NSBlockOperation
- (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