Permalink
Browse files

added flag to force callback on same thread

  • Loading branch information...
1 parent 58e3a36 commit 4ad1d3ce2ee7d7fb91fce4303db5e2f86acf2174 Jeremy Schoenherr committed Mar 30, 2011
Showing with 21 additions and 7 deletions.
  1. +2 −0 Classes/ASIHTTPRequest.h
  2. +19 −7 Classes/ASIHTTPRequest.m
View
@@ -162,6 +162,7 @@ typedef void (^ASIDataBlock)(NSData *data);
// GroupMe Addition.
BOOL shouldAffectNetworkIndicator;
+ BOOL shouldCallbackOnMainThread;
// 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);
@property (assign) BOOL shouldCompressRequestBody;
// GroupMe Addition.
@property (assign) BOOL shouldAffectNetworkIndicator;
+@property (assign) BOOL shouldCallbackOnMainThread;
@property (retain) NSURL *PACurl;
@property (retain) NSString *authenticationScheme;
View
@@ -278,7 +278,8 @@ - (id)initWithURL:(NSURL *)newURL
[self setShouldResetDownloadProgress:YES];
[self setShouldResetUploadProgress:YES];
[self setAllowCompressedResponse:YES];
- [self setShouldAffectNetworkIndicator:YES];
+ [self setShouldAffectNetworkIndicator:YES]; //GroupMe
+ [self setShouldCallbackOnMainThread:YES]; //GroupMe
[self setShouldWaitToInflateCompressedResponses:YES];
[self setDefaultResponseEncoding:NSISOLatin1StringEncoding];
[self setShouldPresentProxyAuthenticationDialog:YES];
@@ -448,7 +449,8 @@ - (void)releaseBlocksOnMainThread
[authenticationNeededBlock release];
authenticationNeededBlock = nil;
}
- [[self class] performSelectorOnMainThread:@selector(releaseBlocks:) withObject:blocks waitUntilDone:[NSThread isMainThread]];
+ [[self class] performSelectorOnMainThread:@selector(releaseBlocks:) withObject:blocks waitUntilDone:[NSThread isMainThread]];
+
}
// Always called on main thread
+ (void)releaseBlocks:(NSArray *)blocks
@@ -1064,8 +1066,10 @@ - (void)startRequest
if ([self isCancelled]) {
return;
}
-
- [self performSelectorOnMainThread:@selector(requestStarted) withObject:nil waitUntilDone:[NSThread isMainThread]];
+ if (shouldCallbackOnMainThread)
+ [self performSelectorOnMainThread:@selector(requestStarted) withObject:nil waitUntilDone:[NSThread isMainThread]];
+ else
+ [self requestStarted];
[self setDownloadComplete:NO];
[self setComplete:NO];
@@ -1946,7 +1950,10 @@ - (void)requestFinished
if ([self error] || [self mainRequest]) {
return;
}
- [self performSelectorOnMainThread:@selector(reportFinished) withObject:nil waitUntilDone:[NSThread isMainThread]];
+ if (shouldCallbackOnMainThread)
+ [self performSelectorOnMainThread:@selector(reportFinished) withObject:nil waitUntilDone:[NSThread isMainThread]];
+ else
+ [self reportFinished];
}
/* ALWAYS CALLED ON MAIN THREAD! */
@@ -2042,8 +2049,11 @@ - (void)failWithError:(NSError *)theError
[failedRequest setError:theError];
}
- [failedRequest performSelectorOnMainThread:@selector(reportFailure) withObject:nil waitUntilDone:[NSThread isMainThread]];
-
+ if (shouldCallbackOnMainThread)
+ [failedRequest performSelectorOnMainThread:@selector(reportFailure) withObject:nil waitUntilDone:[NSThread isMainThread]];
+ else
+ [failedRequest reportFailure];
+
if (!inProgress)
{
// 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
@synthesize clientCertificates;
@synthesize redirectURL;
@synthesize shouldAffectNetworkIndicator; //GroupMe
+@synthesize shouldCallbackOnMainThread; //GroupMe
+
#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
@synthesize shouldContinueWhenAppEntersBackground;
#endif

0 comments on commit 4ad1d3c

Please sign in to comment.