Skip to content

Commit

Permalink
remove manual task clearing
Browse files Browse the repository at this point in the history
URLSession.shared is not being used, calling invalidateAndCancel prior to cleaning up tasks works.
  • Loading branch information
philfi committed Oct 8, 2020
1 parent c44302e commit 20e69d2
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions Sources/Apollo/URLSessionClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,15 @@ open class URLSessionClient: NSObject, URLSessionDelegate, URLSessionTaskDelegat
self.session = nil
self.clearAllTasks()
}

guard let session = self.session else {
// Session's already gone, just cleanup.
cleanup()
return
}

let currentTaskIDs = self.tasks.value.keys
if #available(OSX 10.11, iOS 9.0, *) {
session.getAllTasks { [weak self] tasks in
for task in tasks {
if currentTaskIDs.contains(task.taskIdentifier) {
self?.cancel(task: task)
}
}

cleanup()
}
} else {
// Fallback on earlier versions - note that per docs this does *not* cancel all operations on the shared session.
session.invalidateAndCancel()
cleanup()
}

session.invalidateAndCancel()
cleanup()
}

/// Clears underlying dictionaries of any data related to a particular task identifier.
Expand Down

0 comments on commit 20e69d2

Please sign in to comment.