Skip to content
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

Don't call download completion handler twice #58

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Sources/Jetworking/Client/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,10 @@ extension Client: DownloadExecutorDelegate {

public func downloadExecutor(_ downloadTask: URLSessionDownloadTask, didCompleteWithError error: Error?) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should rename the delegate function to didFailWithError error: Error? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. This is basically the same naming as in the URLSessionDownloadDelegate. We just "convert" two delegate methods (didCompleteWithError and didFinishDownloadingTo) into one completion. And therefore we should keep track when it's appropriate to call the completion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm ok, then we could leave it as is. Can you please add documentation or rethink the visibility of the function? Is it necessary, that it is available from outside of the framework?

// TODO handle response before calling the completion
guard let completionHandler = executingDownloads[downloadTask.identifier]?.completionHandler else { return }
guard
let completionHandler = executingDownloads[downloadTask.identifier]?.completionHandler,
let error = error
else { return }
enqueue(completionHandler(nil, downloadTask.response, error))
}
}
Expand Down
5 changes: 4 additions & 1 deletion Tests/JetworkingTests/ClientTests/ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ final class ClientTests: XCTestCase {
}
) { localURL, response, error in
dispatchPrecondition(condition: .onQueue(DispatchQueue.main))
guard let localURL = localURL else { return }
guard let localURL = localURL else {
XCTFail("Failed to unwrap url")
return
}

do {
let documentsURL = try FileManager.default.url(
Expand Down