Convert restoreFolder to async/await.

This commit is contained in:
Brent Simmons 2024-03-27 16:21:57 -07:00
parent 8eb5a02849
commit 934a8c89fa
9 changed files with 107 additions and 33 deletions

View File

@ -651,8 +651,8 @@ public enum FetchType {
delegate.renameFolder(for: self, with: folder, to: name, completion: completion)
}
public func restoreFolder(_ folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
delegate.restoreFolder(for: self, folder: folder, completion: completion)
public func restoreFolder(_ folder: Folder) async throws {
try await delegate.restoreFolder(for: self, folder: folder)
}
func clearFeedMetadata(_ feed: Feed) {

View File

@ -43,7 +43,7 @@ import Secrets
func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result<Void, Error>) -> Void)
func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> Void)
func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void)
func restoreFolder(for account: Account, folder: Folder) async throws
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) async throws
// Called at the end of accounts init method.

View File

@ -435,7 +435,21 @@ enum CloudKitAccountDelegateError: LocalizedError {
}
func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
func restoreFolder(for account: Account, folder: Folder) async throws {
try await withCheckedThrowingContinuation { continuation in
self.restoreFolder(for: account, folder: folder) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
private func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
guard let name = folder.name else {
completion(.failure(LocalAccountDelegateError.invalidParameter))
return

View File

@ -575,7 +575,21 @@ final class FeedbinAccountDelegate: AccountDelegate {
}
func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
func restoreFolder(for account: Account, folder: Folder) async throws {
try await withCheckedThrowingContinuation { continuation in
self.restoreFolder(for: account, folder: folder) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
private func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
let group = DispatchGroup()

View File

@ -555,7 +555,21 @@ final class FeedlyAccountDelegate: AccountDelegate {
}
}
@MainActor func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
func restoreFolder(for account: Account, folder: Folder) async throws {
try await withCheckedThrowingContinuation { continuation in
self.restoreFolder(for: account, folder: folder) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
private func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
let group = DispatchGroup()
for feed in folder.topLevelFeeds {

View File

@ -135,9 +135,8 @@ final class LocalAccountDelegate: AccountDelegate {
completion(.success(()))
}
func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
func restoreFolder(for account: Account, folder: Folder) async throws {
account.addFolder(folder)
completion(.success(()))
}
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) async throws {

View File

@ -603,7 +603,21 @@ final class NewsBlurAccountDelegate: AccountDelegate {
}
}
func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> ()) {
func restoreFolder(for account: Account, folder: Folder) async throws {
try await withCheckedThrowingContinuation { continuation in
self.restoreFolder(for: account, folder: folder) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
private func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> ()) {
guard let folderName = folder.name else {
completion(.failure(NewsBlurError.invalidParameter))
return

View File

@ -627,7 +627,21 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
}
func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
func restoreFolder(for account: Account, folder: Folder) async throws {
try await withCheckedThrowingContinuation { continuation in
self.restoreFolder(for: account, folder: folder) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
private func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result<Void, Error>) -> Void) {
let group = DispatchGroup()

View File

@ -196,16 +196,21 @@ import Core
private func restoreFolder() {
guard let account = account, let folder = folder else {
guard let account, let folder else {
return
}
BatchUpdate.shared.start()
account.restoreFolder(folder) { result in
BatchUpdate.shared.end()
self.checkResult(result)
}
Task { @MainActor in
BatchUpdate.shared.start()
do {
try await account.restoreFolder(folder)
BatchUpdate.shared.end()
} catch {
BatchUpdate.shared.end()
self.errorHandler(error)
}
}
}
private func checkResult(_ result: Result<Void, Error>) {