Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added flag to force callback on same thread

  • Loading branch information...
commit 4ad1d3ce2ee7d7fb91fce4303db5e2f86acf2174 1 parent 58e3a36
authored March 30, 2011
2  Classes/ASIHTTPRequest.h
@@ -162,6 +162,7 @@ typedef void (^ASIDataBlock)(NSData *data);
162 162
 
163 163
 	// GroupMe Addition.
164 164
 	BOOL shouldAffectNetworkIndicator;
  165
+    BOOL shouldCallbackOnMainThread;
165 166
 	
166 167
 	
167 168
 	// When downloadDestinationPath is set, the result of this request will be downloaded to the file at this location
@@ -951,6 +952,7 @@ typedef void (^ASIDataBlock)(NSData *data);
951 952
 @property (assign) BOOL shouldCompressRequestBody;
952 953
 // GroupMe Addition.
953 954
 @property (assign) BOOL shouldAffectNetworkIndicator;
  955
+@property (assign) BOOL shouldCallbackOnMainThread;
954 956
 
955 957
 @property (retain) NSURL *PACurl;
956 958
 @property (retain) NSString *authenticationScheme;
26  Classes/ASIHTTPRequest.m
@@ -278,7 +278,8 @@ - (id)initWithURL:(NSURL *)newURL
278 278
 	[self setShouldResetDownloadProgress:YES];
279 279
 	[self setShouldResetUploadProgress:YES];
280 280
 	[self setAllowCompressedResponse:YES];
281  
-	[self setShouldAffectNetworkIndicator:YES];
  281
+	[self setShouldAffectNetworkIndicator:YES]; //GroupMe
  282
+    [self setShouldCallbackOnMainThread:YES]; //GroupMe
282 283
 	[self setShouldWaitToInflateCompressedResponses:YES];
283 284
 	[self setDefaultResponseEncoding:NSISOLatin1StringEncoding];
284 285
 	[self setShouldPresentProxyAuthenticationDialog:YES];
@@ -448,7 +449,8 @@ - (void)releaseBlocksOnMainThread
448 449
 		[authenticationNeededBlock release];
449 450
 		authenticationNeededBlock = nil;
450 451
 	}
451  
-	[[self class] performSelectorOnMainThread:@selector(releaseBlocks:) withObject:blocks waitUntilDone:[NSThread isMainThread]];
  452
+    [[self class] performSelectorOnMainThread:@selector(releaseBlocks:) withObject:blocks waitUntilDone:[NSThread isMainThread]];
  453
+        
452 454
 }
453 455
 // Always called on main thread
454 456
 + (void)releaseBlocks:(NSArray *)blocks
@@ -1064,8 +1066,10 @@ - (void)startRequest
1064 1066
 	if ([self isCancelled]) {
1065 1067
 		return;
1066 1068
 	}
1067  
-	
1068  
-	[self performSelectorOnMainThread:@selector(requestStarted) withObject:nil waitUntilDone:[NSThread isMainThread]];
  1069
+	if (shouldCallbackOnMainThread)
  1070
+        [self performSelectorOnMainThread:@selector(requestStarted) withObject:nil waitUntilDone:[NSThread isMainThread]];
  1071
+    else
  1072
+        [self requestStarted];
1069 1073
 	
1070 1074
 	[self setDownloadComplete:NO];
1071 1075
 	[self setComplete:NO];
@@ -1946,7 +1950,10 @@ - (void)requestFinished
1946 1950
 	if ([self error] || [self mainRequest]) {
1947 1951
 		return;
1948 1952
 	}
1949  
-	[self performSelectorOnMainThread:@selector(reportFinished) withObject:nil waitUntilDone:[NSThread isMainThread]];
  1953
+    if (shouldCallbackOnMainThread)
  1954
+        [self performSelectorOnMainThread:@selector(reportFinished) withObject:nil waitUntilDone:[NSThread isMainThread]];
  1955
+    else
  1956
+        [self reportFinished];
1950 1957
 }
1951 1958
 
1952 1959
 /* ALWAYS CALLED ON MAIN THREAD! */
@@ -2042,8 +2049,11 @@ - (void)failWithError:(NSError *)theError
2042 2049
 		[failedRequest setError:theError];
2043 2050
 	}
2044 2051
 
2045  
-	[failedRequest performSelectorOnMainThread:@selector(reportFailure) withObject:nil waitUntilDone:[NSThread isMainThread]];
2046  
-	
  2052
+    if (shouldCallbackOnMainThread)
  2053
+        [failedRequest performSelectorOnMainThread:@selector(reportFailure) withObject:nil waitUntilDone:[NSThread isMainThread]];
  2054
+	else
  2055
+        [failedRequest reportFailure];
  2056
+    
2047 2057
     if (!inProgress)
2048 2058
     {
2049 2059
         // if we're not in progress, we can't notify the queue we've finished (doing so can cause a crash later on)
@@ -4580,6 +4590,8 @@ - (void)setRequestRedirectedBlock:(ASIBasicBlock)aRedirectBlock
4580 4590
 @synthesize clientCertificates;
4581 4591
 @synthesize redirectURL;
4582 4592
 @synthesize shouldAffectNetworkIndicator; //GroupMe
  4593
+@synthesize shouldCallbackOnMainThread; //GroupMe
  4594
+
4583 4595
 #if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
4584 4596
 @synthesize shouldContinueWhenAppEntersBackground;
4585 4597
 #endif

0 notes on commit 4ad1d3c

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