Skip to content

Commit 95194e6

Browse files
pcuencadavidkoski
andauthored
Fix download progress (#60)
Fixes #59. Co-authored-by: davidkoski <davidkoski@users.noreply.github.com>
1 parent 72fc1f7 commit 95194e6

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Sources/Hub/HubApi.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,21 +157,21 @@ public extension HubApi {
157157
@discardableResult
158158
func download(progressHandler: @escaping (Double) -> Void) async throws -> URL {
159159
guard !downloaded else { return destination }
160-
160+
161161
try prepareDestination()
162162
let downloader = Downloader(from: source, to: destination, using: hfToken)
163163
let downloadSubscriber = downloader.downloadState.sink { state in
164164
if case .downloading(let progress) = state {
165165
progressHandler(progress)
166166
}
167167
}
168-
// We need to assign the cancellable to a var so we keep receiving events, so we suppress the "unused var" warning here
169-
let _ = downloadSubscriber
170-
try downloader.waitUntilDone()
168+
_ = try withExtendedLifetime(downloadSubscriber) {
169+
try downloader.waitUntilDone()
170+
}
171171
return destination
172172
}
173173
}
174-
174+
175175
@discardableResult
176176
func snapshot(from repo: Repo, matching globs: [String] = [], progressHandler: @escaping (Progress) -> Void = { _ in }) async throws -> URL {
177177
let filenames = try await getFilenames(from: repo, matching: globs)

0 commit comments

Comments
 (0)