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:
Brent Simmons 2024-04-06 18:20:48 -07:00
parent 2c91765896
commit feb1e77424

View File

@ -86,7 +86,9 @@ public protocol DownloadSessionDelegate {
extension DownloadSession: URLSessionTaskDelegate {
public func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
nonisolated public func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
MainActor.assumeIsolated {
tasksInProgress.remove(task)
guard let info = infoForTask(task) else {
@ -99,9 +101,11 @@ extension DownloadSession: URLSessionTaskDelegate {
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) {
MainActor.assumeIsolated {
if response.statusCode == 301 || response.statusCode == 308 {
if let oldURLString = task.originalRequest?.url?.absoluteString, let newURLString = request.url?.absoluteString {
cacheRedirect(oldURLString, newURLString)
@ -111,6 +115,7 @@ extension DownloadSession: URLSessionTaskDelegate {
completionHandler(request)
}
}
}
// MARK: - URLSessionDataDelegate