From 38aa43ca6ebfb9fd4739a8ee04b4d6d2476f0c94 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 6 Nov 2025 21:10:04 -0800 Subject: [PATCH] Convert to async/await. --- Modules/Account/Sources/Account/Account.swift | 9 ++++++++- Modules/Account/Sources/Account/AccountDelegate.swift | 2 +- .../Account/CloudKit/CloudKitAccountDelegate.swift | 10 +++++++++- .../Account/Feedbin/FeedbinAccountDelegate.swift | 10 +++++++++- .../Sources/Account/Feedly/FeedlyAccountDelegate.swift | 10 +++++++++- .../Account/LocalAccount/LocalAccountDelegate.swift | 3 +-- .../Account/NewsBlur/NewsBlurAccountDelegate.swift | 10 +++++++++- .../Account/ReaderAPI/ReaderAPIAccountDelegate.swift | 10 +++++++++- 8 files changed, 55 insertions(+), 9 deletions(-) diff --git a/Modules/Account/Sources/Account/Account.swift b/Modules/Account/Sources/Account/Account.swift index 86937c696..8a5a13bc6 100644 --- a/Modules/Account/Sources/Account/Account.swift +++ b/Modules/Account/Sources/Account/Account.swift @@ -591,7 +591,14 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } public func moveFeed(_ feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { - delegate.moveFeed(for: self, with: feed, from: from, to: to, completion: completion) + Task { @MainActor in + do { + try await delegate.moveFeed(for: self, with: feed, from: from, to: to) + completion(.success(())) + } catch { + completion(.failure(error)) + } + } } public func renameFeed(_ feed: Feed, to name: String, completion: @escaping (Result) -> Void) { diff --git a/Modules/Account/Sources/Account/AccountDelegate.swift b/Modules/Account/Sources/Account/AccountDelegate.swift index 233238a18..b9bdfe175 100644 --- a/Modules/Account/Sources/Account/AccountDelegate.swift +++ b/Modules/Account/Sources/Account/AccountDelegate.swift @@ -40,7 +40,7 @@ protocol AccountDelegate { @MainActor func renameFeed(for account: Account, with feed: Feed, to name: String) async throws func addFeed(for account: Account, with: Feed, to container: Container, completion: @escaping (Result) -> Void) func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result) -> Void) - func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) + @MainActor func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container) async throws func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result) -> Void) func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result) -> Void) diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index 3736d3ce1..eb0bce0b4 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -258,7 +258,15 @@ final class CloudKitAccountDelegate: AccountDelegate { } } - func moveFeed(for account: Account, with feed: Feed, from fromContainer: Container, to toContainer: Container, completion: @escaping (Result) -> Void) { + @MainActor func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container) async throws { + try await withCheckedThrowingContinuation{ continuation in + moveFeed(for: account, with: feed, from: from, to: to) { result in + continuation.resume(with: result) + } + } + } + + private func moveFeed(for account: Account, with feed: Feed, from fromContainer: Container, to toContainer: Container, completion: @escaping (Result) -> Void) { syncProgress.addToNumberOfTasksAndRemaining(1) accountZone.moveFeed(feed, from: fromContainer, to: toContainer) { result in self.syncProgress.completeTask() diff --git a/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift b/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift index 137150f20..beaef6c83 100644 --- a/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift @@ -402,7 +402,15 @@ final class FeedbinAccountDelegate: AccountDelegate { } } - func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { + @MainActor func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container) async throws { + try await withCheckedThrowingContinuation{ continuation in + moveFeed(for: account, with: feed, from: from, to: to) { result in + continuation.resume(with: result) + } + } + } + + private func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { if from is Account { addFeed(for: account, with: feed, to: to, completion: completion) } else { diff --git a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift index 0921676b3..e358216f5 100644 --- a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift +++ b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift @@ -470,7 +470,15 @@ final class FeedlyAccountDelegate: AccountDelegate { folder.removeFeed(feed) } - func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { + @MainActor func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container) async throws { + try await withCheckedThrowingContinuation{ continuation in + moveFeed(for: account, with: feed, from: from, to: to) { result in + continuation.resume(with: result) + } + } + } + + private func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { guard let from = from as? Folder, let to = to as? Folder else { return DispatchQueue.main.async { completion(.failure(FeedlyAccountDelegateError.addFeedChooseFolder)) diff --git a/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift b/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift index 06bf3493c..73b54483f 100644 --- a/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift +++ b/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift @@ -129,10 +129,9 @@ final class LocalAccountDelegate: AccountDelegate { completion(.success(())) } - func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { + @MainActor func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container) async throws { from.removeFeed(feed) to.addFeed(feed) - completion(.success(())) } func addFeed(for account: Account, with feed: Feed, to container: Container, completion: @escaping (Result) -> Void) { diff --git a/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift b/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift index 0c2a21b10..ecabccade 100644 --- a/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift +++ b/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift @@ -535,7 +535,15 @@ final class NewsBlurAccountDelegate: AccountDelegate { deleteFeed(for: account, with: feed, from: container, completion: completion) } - func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> ()) { + @MainActor func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container) async throws { + try await withCheckedThrowingContinuation{ continuation in + moveFeed(for: account, with: feed, from: from, to: to) { result in + continuation.resume(with: result) + } + } + } + + private func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> ()) { guard let feedID = feed.externalID else { completion(.failure(NewsBlurError.invalidParameter)) return diff --git a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift index b84457821..9ab7d20b3 100644 --- a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -507,7 +507,15 @@ final class ReaderAPIAccountDelegate: AccountDelegate { } } - func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { + @MainActor func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container) async throws { + try await withCheckedThrowingContinuation{ continuation in + moveFeed(for: account, with: feed, from: from, to: to) { result in + continuation.resume(with: result) + } + } + } + + private func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { if from is Account { addFeed(for: account, with: feed, to: to, completion: completion) } else {