aboutsummaryrefslogtreecommitdiffstats
path: root/Source/CustomQuery.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/CustomQuery.m')
-rw-r--r--Source/CustomQuery.m10
1 files changed, 8 insertions, 2 deletions
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index 93567aa5..55c87129 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -364,7 +364,13 @@
if (customQueryCallbackMethod)
encodedCallbackMethod = [NSValue valueWithBytes:&customQueryCallbackMethod objCType:@encode(SEL)];
NSDictionary *taskArguments = [NSDictionary dictionaryWithObjectsAndKeys:queries, @"queries", encodedCallbackMethod, @"callback", nil];
- [NSThread detachNewThreadSelector:@selector(performQueriesTask:) toTarget:self withObject:taskArguments];
+
+ // If a helper thread is already running, execute inline - otherwise detach a new thread for the queries
+ if ([NSThread isMainThread]) {
+ [NSThread detachNewThreadSelector:@selector(performQueriesTask:) toTarget:self withObject:taskArguments];
+ } else {
+ [self performQueriesTask:taskArguments];
+ }
}
- (void)performQueriesTask:(NSDictionary *)taskArguments
@@ -745,7 +751,7 @@
// Set up the callback if present
if ([taskArguments objectForKey:@"callback"]) {
[[taskArguments objectForKey:@"callback"] getValue:&callbackMethod];
- [self performSelectorOnMainThread:callbackMethod withObject:nil waitUntilDone:NO];
+ [self performSelectorOnMainThread:callbackMethod withObject:nil waitUntilDone:YES];
}
[tableDocumentInstance endTask];