Skip to content

Commit

Permalink
NSURLSession: call getTasks callbacks on delegate queue
Browse files Browse the repository at this point in the history
Matches the documented behavior.
  • Loading branch information
triplef committed Jan 16, 2023
1 parent 41b08d0 commit 1715dfe
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Source/NSURLSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ - (void) finishTasksAndInvalidate
void (^invalidateSessionCallback)(void) =
^{
if (nil == _delegate) return;
[self.delegateQueue addOperationWithBlock:

[[self delegateQueue] addOperationWithBlock:
^{
if ([_delegate respondsToSelector: @selector(URLSession:didBecomeInvalidWithError:)])
{
Expand Down Expand Up @@ -298,7 +299,7 @@ - (void) invalidateAndCancel
return;
}

[_delegateQueue addOperationWithBlock:
[[self delegateQueue] addOperationWithBlock:
^{
if ([_delegate respondsToSelector: @selector(URLSession:didBecomeInvalidWithError:)])
{
Expand Down Expand Up @@ -405,14 +406,20 @@ - (void) getTasksWithCompletionHandler: (void (^)(GS_GENERIC_CLASS(NSArray, NSUR
return [task isKindOfClass:[NSURLSessionDownloadTask class]];
}]];

completionHandler(dataTasks, uploadTasks, downloadTasks);
[[self delegateQueue] addOperationWithBlock:
^{
completionHandler(dataTasks, uploadTasks, downloadTasks);
}];
}

- (void) getAllTasksWithCompletionHandler: (void (^)(GS_GENERIC_CLASS(NSArray, __kindof NSURLSessionTask*) *tasks))completionHandler
{
NSArray *allTasks = [_taskRegistry allTasks];

completionHandler(allTasks);
[[self delegateQueue] addOperationWithBlock:
^{
completionHandler(allTasks);
}];
}

- (void) addTask: (NSURLSessionTask*)task
Expand Down

0 comments on commit 1715dfe

Please sign in to comment.