From d2c1afda6aac0463a3f7aedbd4983ac43fbcfe76 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Fri, 7 Nov 2025 09:46:39 -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 09c66e513..784d26f51 100644 --- a/Modules/Account/Sources/Account/Account.swift +++ b/Modules/Account/Sources/Account/Account.swift @@ -637,7 +637,14 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } public func restoreFolder(_ folder: Folder, completion: @escaping (Result) -> Void) { - delegate.restoreFolder(for: self, folder: folder, completion: completion) + Task { @MainActor in + do { + try await delegate.restoreFolder(for: self, folder: folder) + completion(.success(())) + } catch { + completion(.failure(error)) + } + } } func clearFeedMetadata(_ feed: Feed) { diff --git a/Modules/Account/Sources/Account/AccountDelegate.swift b/Modules/Account/Sources/Account/AccountDelegate.swift index 375a0e6d5..d79df594c 100644 --- a/Modules/Account/Sources/Account/AccountDelegate.swift +++ b/Modules/Account/Sources/Account/AccountDelegate.swift @@ -43,7 +43,7 @@ protocol AccountDelegate { @MainActor func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container) async throws @MainActor func restoreFeed(for account: Account, feed: Feed, container: Container) async throws - func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result) -> Void) + @MainActor func restoreFolder(for account: Account, folder: Folder) async throws func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result) -> Void) diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index b9dc27e86..3f1382d33 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -416,7 +416,15 @@ final class CloudKitAccountDelegate: AccountDelegate { } - func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result) -> Void) { + @MainActor func restoreFolder(for account: Account, folder: Folder) async throws { + try await withCheckedThrowingContinuation { continuation in + restoreFolder(for: account, folder: folder) { result in + continuation.resume(with: result) + } + } + } + + private func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result) -> Void) { guard let name = folder.name else { completion(.failure(LocalAccountDelegateError.invalidParameter)) return diff --git a/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift b/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift index 2c0b5ab66..a9b8e2456 100644 --- a/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift @@ -489,7 +489,15 @@ final class FeedbinAccountDelegate: AccountDelegate { } - func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result) -> Void) { + @MainActor func restoreFolder(for account: Account, folder: Folder) async throws { + try await withCheckedThrowingContinuation { continuation in + restoreFolder(for: account, folder: folder) { result in + continuation.resume(with: result) + } + } + } + + private func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result) -> Void) { let group = DispatchGroup() diff --git a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift index 9bfcd7330..1be1b2703 100644 --- a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift +++ b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift @@ -541,7 +541,15 @@ final class FeedlyAccountDelegate: AccountDelegate { } } - func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result) -> Void) { + @MainActor func restoreFolder(for account: Account, folder: Folder) async throws { + try await withCheckedThrowingContinuation { continuation in + restoreFolder(for: account, folder: folder) { result in + continuation.resume(with: result) + } + } + } + + private func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result) -> Void) { let group = DispatchGroup() for feed in folder.topLevelFeeds { diff --git a/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift b/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift index f9f84d8d6..d1f9ec4d2 100644 --- a/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift +++ b/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift @@ -159,9 +159,8 @@ final class LocalAccountDelegate: AccountDelegate { completion(.success(())) } - func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result) -> Void) { + @MainActor func restoreFolder(for account: Account, folder: Folder) async throws { account.addFolder(folder) - completion(.success(())) } func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result) -> Void) { diff --git a/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift b/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift index cf53de8d0..da7861b6a 100644 --- a/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift +++ b/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift @@ -600,7 +600,15 @@ final class NewsBlurAccountDelegate: AccountDelegate { } } - func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result) -> ()) { + @MainActor func restoreFolder(for account: Account, folder: Folder) async throws { + try await withCheckedThrowingContinuation { continuation in + restoreFolder(for: account, folder: folder) { result in + continuation.resume(with: result) + } + } + } + + private func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result) -> ()) { guard let folderName = folder.name 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 29c1b3af8..c9d4f54ee 100644 --- a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -605,7 +605,15 @@ final class ReaderAPIAccountDelegate: AccountDelegate { } - func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result) -> Void) { + @MainActor func restoreFolder(for account: Account, folder: Folder) async throws { + try await withCheckedThrowingContinuation { continuation in + restoreFolder(for: account, folder: folder) { result in + continuation.resume(with: result) + } + } + } + + private func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result) -> Void) { let group = DispatchGroup()