-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add URLSessionDownloadTask.cancel(byProducingResumeData:) #1592
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
Add URLSessionDownloadTask.cancel(byProducingResumeData:) #1592
Conversation
@swift-ci please test |
* | ||
* Instead, we just call the completionHandler directly. | ||
* | ||
* A token Data value is passed to the client to prevent unexpected failures |
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 would be prudent if data was usually expected, but the contract of this method goes:
If the download is resumable, the completion handler is provided with a resumeData object. Your app can later pass this object to a session’s downloadTask(withResumeData:) or downloadTask(withResumeData:completionHandler:) method to create a new task that resumes the download where it left off.
Since we do not yet support resuming on Linux, no downloads are resumable, and so we can safely pass nil
here. Let's not confuse downstream clients into thinking the download is resumable when we can't resume it.
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.
Great point. PR updated, accordingly.
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.
I think I'll request a change. This breaks the contract.
@swift-ci please test |
@swift-ci please test |
🎉 What's the process to merge this in, now that everything is passing? |
Me hitting a button. |
This is an attempt at resolving the implementation for
URLSessionDownloadTask.cancel(byProducingResumeData:)
.This function seems to represent an edge case in portability. After communicating with @phausler, it appears the Objective-C implementation of this relies on an Apple-maintained XPC process to manage the bookmarking of partially downloaded data. Of course, this behavior is not portable to the framework project.
One approach that was considered was serializing the
URLSessionDownloadTask
instance and returning that to the caller as the opaque blob given to the completion handler. However, the Objective-C implementation ofURLSessionTask
does not implement anyNSCoding
flavor publicly, so conformance would need to be implemented in this framework withinternal
or greater access control. But, unfortunately, that functionality is not currently supported in Swift.The approach suggested by @phausler was simply to... hardcode calling the completion block. This is what was done in this PR.
The only thing worth highlighting about the approach is that a token
Data
instance is passed to the completion block to prevent unexpected failures that may be caused from passingnil
instead.Open Issues:
downloadTask(withResumeData:)
(and related) would remain broken by this approach. What should be done with these functions?