Continue adopting async/await.

This commit is contained in:
Brent Simmons
2023-07-14 14:29:58 -07:00
parent 5c3cbd30f7
commit 9df917c0fb
4 changed files with 20 additions and 14 deletions

View File

@@ -616,7 +616,11 @@ public enum FetchType {
public func moveFeed(_ feed: Feed, from: Container, to: Container, completion: @escaping (Result<Void, Error>) -> Void) {
delegate.moveFeed(for: self, with: feed, from: from, to: to, completion: completion)
}
public func rename(_ feed: Feed, to name: String) async throws {
try await delegate.renameFeed(for: self, feed: feed, name: name)
}
public func renameFeed(_ feed: Feed, to name: String, completion: @escaping (Result<Void, Error>) -> Void) {
delegate.renameFeed(for: self, with: feed, to: name, completion: completion)
}

View File

@@ -210,6 +210,13 @@ public final class Feed: FeedProtocol, Renamable, Hashable, ObservableObject {
// MARK: - Renamable
@MainActor public func rename(to newName: String) async throws {
guard let account else {
return
}
try await account.rename(self, to: newName)
}
@MainActor public func rename(to newName: String, completion: @escaping (Result<Void, Error>) -> Void) {
guard let account = account else { return }
account.renameFeed(self, to: newName, completion: completion)

View File

@@ -229,11 +229,10 @@ extension SidebarViewController: RenameWindowControllerDelegate {
func renameWindowController(_ windowController: RenameWindowController, didRenameObject object: Any, withNewName name: String) {
if let feed = object as? Feed {
feed.rename(to: name) { result in
switch result {
case .success:
break
case .failure(let error):
Task { @MainActor in
do {
try await feed.rename(to: name)
} catch let error {
NSApplication.shared.presentError(error)
}
}

View File

@@ -1443,13 +1443,10 @@ private extension MasterFeedViewController {
}
if let feed = feed as? Feed {
feed.rename(to: name) { result in
switch result {
case .success:
break
case .failure(let error):
self?.presentError(error)
}
do {
try await feed.rename(to: name)
} catch let error {
self?.presentError(error)
}
} else if let folder = feed as? Folder {
folder.rename(to: name) { result in
@@ -1461,7 +1458,6 @@ private extension MasterFeedViewController {
}
}
}
}
alertController.addAction(renameAction)