Skip to content

Commit

Permalink
chore: Clear defer use to track progress
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye committed Jul 21, 2023
1 parent e66a3ce commit e7fabfa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ public final class ItemProviderFileRepresentation: NSObject, ProgressResultable
progress.addChild(completionProgress, withPendingUnitCount: Self.progressStep)

let loadURLProgress = itemProvider.loadFileRepresentation(forTypeIdentifier: fileIdentifierToUse) { [self] fileProviderURL, error in
guard let fileProviderURL, error == nil else {
defer {
completionProgress.completedUnitCount += Self.progressStep
}

guard let fileProviderURL, error == nil else {
flowToAsync.sendFailure(error ?? ErrorDomain.UnableToLoadFile)
return
}
Expand All @@ -88,10 +91,8 @@ public final class ItemProviderFileRepresentation: NSObject, ProgressResultable
let temporaryFileURL = temporaryURL.appendingPathComponent(fileName)
try fileManager.copyItem(atPath: fileProviderURL.path, toPath: temporaryFileURL.path)

completionProgress.completedUnitCount += Self.progressStep
flowToAsync.sendSuccess(temporaryFileURL)
} catch {
completionProgress.completedUnitCount += Self.progressStep
flowToAsync.sendFailure(error)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ public final class ItemProviderWeblocRepresentation: NSObject, ProgressResultabl
progress.addChild(completionProgress, withPendingUnitCount: Self.progressStep)

let loadURLProgress = itemProvider.loadObject(ofClass: URL.self) { [self] path, error in
defer {
completionProgress.completedUnitCount += Self.progressStep
}

guard error == nil, let path: URL = path else {
let error: Error = error ?? ErrorDomain.unableToLoadURLForObject
completionProgress.completedUnitCount += Self.progressStep
flowToAsync.sendFailure(error)
return
}
Expand All @@ -75,10 +78,8 @@ public final class ItemProviderWeblocRepresentation: NSObject, ProgressResultabl
let data = try encoder.encode(content)
try data.write(to: targetURL)

completionProgress.completedUnitCount += Self.progressStep
flowToAsync.sendSuccess(targetURL)
} catch {
completionProgress.completedUnitCount += Self.progressStep
flowToAsync.sendFailure(error)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public final class ItemProviderZipRepresentation: NSObject, ProgressResultable {
// compress content of folder and move it somewhere we can safely store it for upload
var error: NSError?
coordinator.coordinate(readingItemAt: path, options: [.forUploading], error: &error) { zipURL in
defer {
completionProgress.completedUnitCount += Self.progressStep
}

do {
@InjectService var pathProvider: AppGroupPathProvidable
let tmpDirectoryURL = pathProvider.tmpDirectoryURL
Expand All @@ -88,10 +92,8 @@ public final class ItemProviderZipRepresentation: NSObject, ProgressResultable {

try self.fileManager.moveItem(at: zipURL, to: targetURL)

completionProgress.completedUnitCount += Self.progressStep
self.flowToAsync.sendSuccess(targetURL)
} catch {
completionProgress.completedUnitCount += Self.progressStep
self.flowToAsync.sendFailure(error)
}
}
Expand Down

0 comments on commit e7fabfa

Please sign in to comment.