Convert delete to async await.

This commit is contained in:
Brent Simmons 2024-05-21 22:18:26 -07:00
parent 43a94793a7
commit 4323c24c88
1 changed files with 27 additions and 39 deletions

View File

@ -47,17 +47,14 @@ import Core
func perform() {
let group = DispatchGroup()
for itemSpecifier in itemSpecifiers {
group.enter()
itemSpecifier.delete() {
group.leave()
}
}
Task { @MainActor in
group.notify(queue: DispatchQueue.main) {
self.treeController?.rebuild()
self.registerUndo()
for itemSpecifier in itemSpecifiers {
await itemSpecifier.delete()
}
treeController?.rebuild()
registerUndo()
}
}
@ -143,43 +140,34 @@ import Core
}
func delete(completion: @escaping () -> Void) {
func delete() async {
if let feed = feed {
if let feed {
guard let container = path.resolveContainer() else {
completion()
return
}
BatchUpdate.shared.start()
Task { @MainActor in
do {
try await account?.removeFeed(feed, from: container)
BatchUpdate.shared.end()
completion()
} catch {
BatchUpdate.shared.end()
completion()
self.errorHandler(error)
}
do {
try await account?.removeFeed(feed, from: container)
BatchUpdate.shared.end()
} catch {
BatchUpdate.shared.end()
errorHandler(error)
}
} else if let folder = folder {
} else if let folder {
BatchUpdate.shared.start()
Task { @MainActor in
do {
try await account?.removeFolder(folder)
BatchUpdate.shared.end()
completion()
} catch {
BatchUpdate.shared.end()
completion()
self.errorHandler(error)
}
do {
try await account?.removeFolder(folder)
BatchUpdate.shared.end()
} catch {
BatchUpdate.shared.end()
errorHandler(error)
}
}
}