Created
July 26, 2012 09:33
-
-
Save pita5/3181217 to your computer and use it in GitHub Desktop.
This file contains hidden or 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)_updateResults:(void (^)(void))block caller:(dispatch_queue_t)callerqueue | |
{ | |
__unsafe_unretained NUData* wself = self; | |
dispatch_sync(_serial_results_queue, ^{ | |
NSManagedObjectContext* ctx = updateContext; | |
__block NSArray* results = nil; | |
[ctx performBlockAndWait:^{ | |
__autoreleasing NSError* fetchError = nil; | |
NSFetchRequest* request = [[NSFetchRequest alloc] initWithEntityName:@"Event"]; | |
results = [ctx executeFetchRequest:request error:&fetchError]; | |
}]; | |
dispatch_group_t group = dispatch_group_create(); | |
dispatch_queue_t background = dispatch_queue_create("com.ft.results.update.concurrent", DISPATCH_QUEUE_CONCURRENT); | |
for (SKEvent* event in results) | |
{ | |
dispatch_group_async(group, background, ^{ | |
[wself __updateResults:^{} forEvent:event caller:callerqueue]; | |
}); | |
} | |
dispatch_group_wait(group, DISPATCH_TIME_FOREVER); | |
dispatch_release(group); | |
dispatch_release(background); | |
void(^block_c)(void) = ^(void) { | |
NSLog(@"completed update results"); | |
if (block) block(); | |
}; | |
// Notify Observers | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
[[NSNotificationCenter defaultCenter] postNotificationName:kSKNotifResultsDownloaded object:nil]; | |
}); | |
// Execute completion block | |
dispatch_async(callerqueue, block_c); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment