Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed the code to always push the request on the main thread and added autorelease pool to properly release objects created on the new thread. #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions src/SeriouslyOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,33 @@ - (id)initWithRequest:(NSURLRequest *)urlRequest handler:(SeriouslyHandler)handl
return self;
}

- (void)start {
if (self.isCanceled || self.isFinished) return;

if (![NSThread isMainThread]) {
[self performSelectorOnMainThread:@selector(start) withObject:nil waitUntilDone:NO];
return;
}

- (void)main {

if (self.isCanceled || self.isFinished) return;

KVO_SET(isExecuting, YES);

_connection = [[NSURLConnection alloc] initWithRequest:_urlRequest delegate:self];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

_connection = [[NSURLConnection alloc] initWithRequest:_urlRequest delegate:self];
[_connection start];

if (![NSThread isMainThread]) {
//keep the thread alive while connection is executing
//without this NSURLConnection delegate is not called
NSRunLoop *theRL = [NSRunLoop currentRunLoop];
while ([self isExecuting] && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]){
//nothing to do
}
}

[pool drain];

}

- (void)start {

[self main];
}

- (void)cancel {
Expand Down