Skip to content

Instantly share code, notes, and snippets.

@jrmsklar
Created July 23, 2014 20:29
Show Gist options
  • Save jrmsklar/e414eab75b9401953d8f to your computer and use it in GitHub Desktop.
Save jrmsklar/e414eab75b9401953d8f to your computer and use it in GitHub Desktop.
- (void)someMethodThatDoesATimeIntensiveTaskWithCompletionBlock:(void (^)(void))block
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul), ^{
while (someCondition) {
NSErorr *error;
// Do the time intensive task here, passing the error object along
if (error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (block) {
block();
}
return;
});
}
}
dispatch_async(dispatch_get_main_queue(), ^{
if (block) {
block();
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment