Skip to content

Instantly share code, notes, and snippets.

@pita5
Created July 24, 2012 21:56
Show Gist options
  • Save pita5/3172930 to your computer and use it in GitHub Desktop.
Save pita5/3172930 to your computer and use it in GitHub Desktop.
- (void)update:(void (^)(void))block
{
__unsafe_unretained NUData* wself = self;
dispatch_queue_t caller = dispatch_get_current_queue();
dispatch_async(queue, ^{
NSLog(@"updating");
// dispatch these tasks concurrently, wait the queue until done
dispatch_queue_t async_tasks_queue = dispatch_queue_create("com.ft.update.async", DISPATCH_QUEUE_CONCURRENT);
dispatch_group_t async_tasks_group = dispatch_group_create();
// update galley
dispatch_group_async(async_tasks_group, async_tasks_queue, ^{
[wself _updateGalleryAndVideos:^{} caller:caller];
});
// update manufacturer results
dispatch_group_async(async_tasks_group, async_tasks_queue, ^{
[wself _updateManufacturerResults:^{} caller:caller];
});
// update driver results
dispatch_group_async(async_tasks_group, async_tasks_queue, ^{
[wself _updateDriverResults:^{} caller:caller];
});
// update stages
dispatch_group_async(async_tasks_group, async_tasks_queue, ^{
[wself _updateStages:^{} caller:caller];
});
// update events and event entries
dispatch_group_async(async_tasks_group, async_tasks_queue, ^{
[wself _updateEvents:^{} caller:caller];
[wself _updateEntries:^{} caller:caller];
});
dispatch_group_wait(async_tasks_group, DISPATCH_TIME_FOREVER);
dispatch_release(async_tasks_group), async_tasks_group = NULL;
dispatch_release(async_tasks_queue), async_tasks_queue = NULL;
// Fire completion block
dispatch_async(caller, ^{
NSLog(@"completed update");
if (block) block();
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment