Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [DoThisAtbackground ^{
- LoadData ();
- [DoThisAtForeground ^{
- UpdateTableAndView();
- }];
- }];
- - (void)serverPerformDataRequestWithQuery:(NSString *)query andDelegate:(__weak id <ServerDelegate)delegate {
- [currentRequest setFailedBlock:nil];
- [currentRequest cancel];
- currentRequest = [[ASIHTTPRequest alloc] initWithURL:kHOST];
- [currentRequest startAsynchronous];
- }
- - (void)userRequestedNewSearch:(SearchInfo*)searchInfo {
- // Assign this operation a new token, that uniquely identifies this operation.
- uint32_t token = [self nextOperationToken];
- // If your "loading" API has an external abort mechanism, you want to keep
- // track of the in-flight I/O so any existing I/O operations can be canceled
- // before dispatching new work.
- dispatch_async(myQueue, ^{
- // Try to load your data in small pieces, so you can exit as early as
- // possible. If you have to do a monolithic load, that's OK, but this
- // block will not exit until that stops.
- while (! loadIsComplete) {
- if ([self currentToken] != token) return;
- // Load some data, set loadIsComplete when loading completes
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- // One last check before updating the UI...
- if ([self currentToken] != token) return;
- // Do your UI update operations
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement