diff --git a/Account/Sources/Account/Account.swift b/Account/Sources/Account/Account.swift index 1c6f12b21..35a29e794 100644 --- a/Account/Sources/Account/Account.swift +++ b/Account/Sources/Account/Account.swift @@ -436,6 +436,20 @@ public enum FetchType { } } + public func sendArticleStatus() async throws { + + try await withCheckedThrowingContinuation { continuation in + self.sendArticleStatus { result in + switch result { + case .success: + continuation.resume() + case .failure(let error): + continuation.resume(throwing: error) + } + } + } + } + public func syncArticleStatus(completion: ((Result) -> Void)? = nil) { delegate.syncArticleStatus(for: self, completion: completion) } diff --git a/Account/Sources/Account/AccountManager.swift b/Account/Sources/Account/AccountManager.swift index 94b50045b..9f7465562 100644 --- a/Account/Sources/Account/AccountManager.swift +++ b/Account/Sources/Account/AccountManager.swift @@ -274,18 +274,15 @@ import Secrets } - public func sendArticleStatusAll(completion: (() -> Void)? = nil) { - let group = DispatchGroup() - - activeAccounts.forEach { - group.enter() - $0.sendArticleStatus() { _ in - group.leave() - } - } + public func sendArticleStatusAll() async { - group.notify(queue: DispatchQueue.global(qos: .background)) { - completion?() + await withTaskGroup(of: Void.self) { taskGroup in + + for account in activeAccounts { + taskGroup.addTask { + try? await account.sendArticleStatus() + } + } } } diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 6651973e1..0dc48e60c 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -343,7 +343,8 @@ import Sparkle ArticleThemeDownloader.cleanUp() - accountManager.sendArticleStatusAll() { + Task { @MainActor in + await accountManager.sendArticleStatusAll() self.isShutDownSyncDone = true }