Skip to content
Browse files

Now honoring cancellation requests during search

  • Loading branch information...
1 parent 9b0ade4 commit b44d63ae636dfabe61fc46a3adba6f0e05133384 @gresrun committed
Showing with 16 additions and 6 deletions.
  1. +16 −6 GHSidebarNav/GHSidebarSearchViewController.m
View
22 GHSidebarNav/GHSidebarSearchViewController.m
@@ -60,6 +60,11 @@ - (id)initWithSidebarViewController:(GHRevealViewController *)sidebarVC {
return self;
}
+- (void)dealloc {
+ [_timer invalidate];
+ [_searchQueue cancelAllOperations];
+}
+
#pragma mark UIViewController
- (void)viewDidLoad {
[super viewDidLoad];
@@ -162,15 +167,20 @@ - (void)performSearch {
} else {
if (searchDelegate) {
__block GHSidebarSearchViewController *selfRef = self;
- [_searchQueue addOperationWithBlock:^{
+ __block NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
[selfRef.searchDelegate searchResultsForText:text withScope:scope callback:^(NSArray *results){
- [[NSOperationQueue mainQueue] addOperationWithBlock:^{
- [selfRef.mutableEntries removeAllObjects];
- [selfRef.mutableEntries addObjectsFromArray:results];
- [selfRef.searchDisplayController.searchResultsTableView reloadData];
- }];
+ if (![operation isCancelled]) {
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+ if (![operation isCancelled]) {
+ [selfRef.mutableEntries removeAllObjects];
+ [selfRef.mutableEntries addObjectsFromArray:results];
+ [selfRef.searchDisplayController.searchResultsTableView reloadData];
+ }
+ }];
+ }
}];
}];
+ [_searchQueue addOperation:operation];
}
}
}

0 comments on commit b44d63a

Please sign in to comment.
Something went wrong with that request. Please try again.