daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Feb 23rd, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [DoThisAtbackground ^{
  2.   LoadData ();
  3.   [DoThisAtForeground ^{
  4.     UpdateTableAndView();
  5.   }];
  6. }];
  7.    
  8. - (void)serverPerformDataRequestWithQuery:(NSString *)query andDelegate:(__weak id <ServerDelegate)delegate {
  9.   [currentRequest setFailedBlock:nil];
  10.   [currentRequest cancel];
  11.   currentRequest = [[ASIHTTPRequest alloc] initWithURL:kHOST];
  12.   [currentRequest startAsynchronous];
  13. }
  14.    
  15. - (void)userRequestedNewSearch:(SearchInfo*)searchInfo {
  16.     // Assign this operation a new token, that uniquely identifies this operation.
  17.     uint32_t token = [self nextOperationToken];
  18.  
  19.     // If your "loading" API has an external abort mechanism, you want to keep
  20.     // track of the in-flight I/O so any existing I/O operations can be canceled
  21.     // before dispatching new work.
  22.  
  23.     dispatch_async(myQueue, ^{
  24.         // Try to load your data in small pieces, so you can exit as early as
  25.         // possible.  If you have to do a monolithic load, that's OK, but this
  26.         // block will not exit until that stops.  
  27.         while (! loadIsComplete) {
  28.             if ([self currentToken] != token) return;
  29.             // Load some data, set loadIsComplete when loading completes
  30.         }
  31.  
  32.         dispatch_async(dispatch_get_main_queue(), ^{
  33.             // One last check before updating the UI...
  34.             if ([self currentToken] != token) return;
  35.  
  36.             // Do your UI update operations
  37.         });
  38.     });
  39.  
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top