Skip to content

Commit

Permalink
[#39] brilliant find Adam! using a custom run loop mode seems to take…
Browse files Browse the repository at this point in the history
… care of this problem
  • Loading branch information
vickeryj committed Feb 10, 2009
1 parent 949e4dc commit 7573de1
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Classes/lib/Connection.m
Expand Up @@ -68,14 +68,13 @@ + (Response *)sendRequest:(NSMutableURLRequest *)request withUser:(NSString *)us
NSURLConnection *connection = [[[NSURLConnection alloc] initWithRequest:request delegate:connectionDelegate startImmediately:NO] autorelease];
connectionDelegate.connection = connection;

NSRunLoop* runLoop = [NSRunLoop mainRunLoop];

//This needs to run in the main run loop in the default mode
[connection unscheduleFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[connection scheduleInRunLoop:runLoop forMode:NSDefaultRunLoopMode];
//use a custom runloop
static NSString *runLoopMode = @"com.yfactorial.objectiveresource.connectionLoop";
[connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:runLoopMode];
[connection start];
while (![connectionDelegate isDone]) {
[runLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:.3]];
[[NSRunLoop currentRunLoop] runMode:runLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:.3]];
}
Response *resp = [Response responseFrom:(NSHTTPURLResponse *)connectionDelegate.response
withBody:connectionDelegate.data
Expand Down

0 comments on commit 7573de1

Please sign in to comment.