Skip to content
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