Fix concurrency warnings in DownloadSession.
This commit is contained in:
parent
5f82750679
commit
c666028f0b
@ -121,56 +121,60 @@ extension DownloadSession: URLSessionTaskDelegate {
|
|||||||
|
|
||||||
extension DownloadSession: URLSessionDataDelegate {
|
extension DownloadSession: URLSessionDataDelegate {
|
||||||
|
|
||||||
public func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: @escaping (URLSession.ResponseDisposition) -> Void) {
|
nonisolated public func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: @escaping (URLSession.ResponseDisposition) -> Void) {
|
||||||
|
|
||||||
tasksInProgress.insert(dataTask)
|
MainActor.assumeIsolated {
|
||||||
tasksPending.remove(dataTask)
|
tasksInProgress.insert(dataTask)
|
||||||
|
tasksPending.remove(dataTask)
|
||||||
|
|
||||||
if let info = infoForTask(dataTask) {
|
if let info = infoForTask(dataTask) {
|
||||||
info.urlResponse = response
|
info.urlResponse = response
|
||||||
}
|
|
||||||
|
|
||||||
if response.forcedStatusCode == 304 {
|
|
||||||
|
|
||||||
if let representedObject = infoForTask(dataTask)?.representedObject {
|
|
||||||
delegate.downloadSession(self, didReceiveNotModifiedResponse: response, representedObject: representedObject)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
completionHandler(.cancel)
|
if response.forcedStatusCode == 304 {
|
||||||
removeTask(dataTask)
|
|
||||||
|
|
||||||
return
|
if let representedObject = infoForTask(dataTask)?.representedObject {
|
||||||
}
|
delegate.downloadSession(self, didReceiveNotModifiedResponse: response, representedObject: representedObject)
|
||||||
|
}
|
||||||
|
|
||||||
if !response.statusIsOK {
|
completionHandler(.cancel)
|
||||||
|
removeTask(dataTask)
|
||||||
|
|
||||||
if let representedObject = infoForTask(dataTask)?.representedObject {
|
return
|
||||||
delegate.downloadSession(self, didReceiveUnexpectedResponse: response, representedObject: representedObject)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
completionHandler(.cancel)
|
if !response.statusIsOK {
|
||||||
removeTask(dataTask)
|
|
||||||
|
|
||||||
return
|
if let representedObject = infoForTask(dataTask)?.representedObject {
|
||||||
|
delegate.downloadSession(self, didReceiveUnexpectedResponse: response, representedObject: representedObject)
|
||||||
|
}
|
||||||
|
|
||||||
|
completionHandler(.cancel)
|
||||||
|
removeTask(dataTask)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
addDataTaskFromQueueIfNecessary()
|
||||||
|
|
||||||
|
completionHandler(.allow)
|
||||||
}
|
}
|
||||||
|
|
||||||
addDataTaskFromQueueIfNecessary()
|
|
||||||
|
|
||||||
completionHandler(.allow)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
|
nonisolated public func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
|
||||||
|
|
||||||
guard let info = infoForTask(dataTask) else {
|
MainActor.assumeIsolated {
|
||||||
return
|
guard let info = infoForTask(dataTask) else {
|
||||||
}
|
return
|
||||||
info.addData(data)
|
}
|
||||||
|
info.addData(data)
|
||||||
|
|
||||||
if !delegate.downloadSession(self, shouldContinueAfterReceivingData: info.data as Data, representedObject: info.representedObject) {
|
if !delegate.downloadSession(self, shouldContinueAfterReceivingData: info.data as Data, representedObject: info.representedObject) {
|
||||||
|
|
||||||
info.canceled = true
|
info.canceled = true
|
||||||
dataTask.cancel()
|
dataTask.cancel()
|
||||||
removeTask(dataTask)
|
removeTask(dataTask)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user