-
Notifications
You must be signed in to change notification settings - Fork 510
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
Set priority of download data tasks at the right time #490
Changes from all commits
7b99aa9
f35fecf
336fd31
fadaa28
6fe605b
18ca0a3
328c546
409d871
7d7ba93
d019a4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ - (PINRemoteImageDownloadQueue *)initWithMaxConcurrentDownloads:(NSUInteger)maxN | |
{ | ||
if (self = [super init]) { | ||
_maxNumberOfConcurrentDownloads = maxNumberOfConcurrentDownloads; | ||
|
||
_lock = [[PINRemoteLock alloc] initWithName:@"PINRemoteImageDownloadQueue Lock"]; | ||
_highPriorityQueuedOperations = [[NSMutableOrderedSet alloc] init]; | ||
_defaultPriorityQueuedOperations = [[NSMutableOrderedSet alloc] init]; | ||
|
@@ -68,19 +68,21 @@ - (NSURLSessionDataTask *)addDownloadWithSessionManager:(PINURLSessionManager *) | |
priority:(PINRemoteImageManagerPriority)priority | ||
completionHandler:(PINRemoteImageDownloadCompletion)completionHandler | ||
{ | ||
NSURLSessionDataTask *dataTask = [sessionManager dataTaskWithRequest:request completionHandler:^(NSURLSessionTask *task, NSError *error) { | ||
completionHandler(task.response, error); | ||
[self lock]; | ||
[self->_runningTasks removeObject:task]; | ||
[self unlock]; | ||
|
||
[self scheduleDownloadsIfNeeded]; | ||
}]; | ||
|
||
NSURLSessionDataTask *dataTask = [sessionManager dataTaskWithRequest:request | ||
priority:priority | ||
completionHandler:^(NSURLSessionTask *task, NSError *error) { | ||
completionHandler(task.response, error); | ||
[self lock]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need the indentation change here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new priority param made this line too long so I break it into multiple lines hence the new indentation. |
||
[self->_runningTasks removeObject:task]; | ||
[self unlock]; | ||
|
||
[self scheduleDownloadsIfNeeded]; | ||
}]; | ||
|
||
[self setQueuePriority:priority forTask:dataTask addIfNecessary:YES]; | ||
|
||
[self scheduleDownloadsIfNeeded]; | ||
|
||
return dataTask; | ||
} | ||
|
||
|
@@ -105,7 +107,6 @@ - (void)scheduleDownloadsIfNeeded | |
[queue removeObjectAtIndex:0]; | ||
[task resume]; | ||
|
||
|
||
[_runningTasks addObject:task]; | ||
} | ||
[self unlock]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,9 +139,10 @@ - (void)setPriority:(PINRemoteImageManagerPriority)priority | |
[super setPriority:priority]; | ||
if (@available(iOS 8.0, macOS 10.10, tvOS 9.0, watchOS 2.0, *)) { | ||
[self.lock lockWithBlock:^{ | ||
if (self->_progressImage.dataTask) { | ||
self->_progressImage.dataTask.priority = dataTaskPriorityWithImageManagerPriority(priority); | ||
[self.manager.urlSessionTaskQueue setQueuePriority:priority forTask:self->_progressImage.dataTask]; | ||
NSURLSessionDataTask *dataTask = self->_progressImage.dataTask; | ||
if (dataTask) { | ||
dataTask.priority = dataTaskPriorityWithImageManagerPriority(priority); | ||
[self.manager.urlSessionTaskQueue setQueuePriority:priority forTask:dataTask]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No behavior change here, just cache the data task in a variable for better readability. |
||
} | ||
}]; | ||
} | ||
|
@@ -342,10 +343,6 @@ - (void)scheduleDownloadWithRequest:(NSURLRequest *)request | |
} | ||
}]; | ||
}]]; | ||
|
||
if (@available(iOS 8.0, macOS 10.10, tvOS 9.0, watchOS 2.0, *)) { | ||
self->_progressImage.dataTask.priority = dataTaskPriorityWithImageManagerPriority(priority); | ||
} | ||
}]; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This property is actually thread-safe so I thought it'd be a good idea to let clients know that.