-
Notifications
You must be signed in to change notification settings - Fork 20
feat: download stop logic on component unmount #16
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
base: main
Are you sure you want to change the base?
Changes from all commits
a7a2dae
e5b41d5
5eb07f2
7bdf6e9
f76b097
aa4f5ae
02a04a3
b48f62f
9fc69ba
cf2ceeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,10 +94,12 @@ class HybridCactusFileSystem: HybridCactusFileSystemSpec { | |
|
|
||
| let session = URLSession(configuration: .default, delegate: delegate, delegateQueue: nil) | ||
| let task = session.downloadTask(with: url) | ||
|
|
||
| self.activeTask = task | ||
| callback?(0.0) | ||
|
|
||
| let (fileURL, response) = try await delegate.awaitCompletion(for: task) | ||
|
|
||
| self.activeTask = nil | ||
|
|
||
| guard let httpResponse = response as? HTTPURLResponse, | ||
| (200...299).contains(httpResponse.statusCode) | ||
|
|
@@ -121,6 +123,17 @@ class HybridCactusFileSystem: HybridCactusFileSystemSpec { | |
| } | ||
| } | ||
| } | ||
|
|
||
| private var activeTask: URLSessionDownloadTask? | ||
|
||
|
|
||
| func stopDownload(model: String) throws -> Promise<Void> { | ||
| return Promise.async { | ||
| if let task = self.activeTask { | ||
| task.cancel() | ||
| self.activeTask = nil | ||
harryfrzz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| func deleteModel(model: String) throws -> Promise<Void> { | ||
| return Promise.async { | ||
|
|
@@ -145,7 +158,6 @@ class HybridCactusFileSystem: HybridCactusFileSystemSpec { | |
| if !FileManager.default.fileExists(atPath: cactusURL.path) { | ||
| try FileManager.default.createDirectory(at: cactusURL, withIntermediateDirectories: true) | ||
|
|
||
| // Exclude from iCloud backup | ||
| var resourceValues = URLResourceValues() | ||
| resourceValues.isExcludedFromBackup = true | ||
| try cactusURL.setResourceValues(resourceValues) | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Race condition: The
activeConnectionandisCancelledvariables are marked@Volatilebut are not properly synchronized. The check-then-act pattern instopDownload(lines 177-180) is not atomic. Between checkingactiveConnection != nulland callingdisconnect(), another thread could set it to null. Consider using synchronized blocks or a lock to ensure thread safety.