Mark delegate methods as nonisolated to fix concurrency warning. Use MainActor.assumeIsolated because we did specify the main queue for these methods.
This commit is contained in:
parent
2c91765896
commit
feb1e77424
@ -86,29 +86,34 @@ public protocol DownloadSessionDelegate {
|
|||||||
|
|
||||||
extension DownloadSession: URLSessionTaskDelegate {
|
extension DownloadSession: URLSessionTaskDelegate {
|
||||||
|
|
||||||
public func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
|
nonisolated public func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
|
||||||
tasksInProgress.remove(task)
|
|
||||||
|
|
||||||
guard let info = infoForTask(task) else {
|
MainActor.assumeIsolated {
|
||||||
return
|
tasksInProgress.remove(task)
|
||||||
}
|
|
||||||
|
|
||||||
info.error = error
|
guard let info = infoForTask(task) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
delegate.downloadSession(self, downloadDidCompleteForRepresentedObject: info.representedObject, response: info.urlResponse, data: info.data as Data, error: error as NSError?) {
|
info.error = error
|
||||||
self.removeTask(task)
|
|
||||||
|
delegate.downloadSession(self, downloadDidCompleteForRepresentedObject: info.representedObject, response: info.urlResponse, data: info.data as Data, error: error as NSError?) {
|
||||||
|
self.removeTask(task)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping (URLRequest?) -> Void) {
|
nonisolated public func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping (URLRequest?) -> Void) {
|
||||||
|
|
||||||
if response.statusCode == 301 || response.statusCode == 308 {
|
MainActor.assumeIsolated {
|
||||||
if let oldURLString = task.originalRequest?.url?.absoluteString, let newURLString = request.url?.absoluteString {
|
if response.statusCode == 301 || response.statusCode == 308 {
|
||||||
cacheRedirect(oldURLString, newURLString)
|
if let oldURLString = task.originalRequest?.url?.absoluteString, let newURLString = request.url?.absoluteString {
|
||||||
|
cacheRedirect(oldURLString, newURLString)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
completionHandler(request)
|
completionHandler(request)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user