Convert syncArticleStatusAll to async/await.
This commit is contained in:
parent
4a5cb237a0
commit
028df3a8f8
|
@ -440,6 +440,20 @@ public enum FetchType {
|
|||
delegate.syncArticleStatus(for: self, completion: completion)
|
||||
}
|
||||
|
||||
public func syncArticleStatus() async throws {
|
||||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
self.syncArticleStatus { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume()
|
||||
case .failure(let error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func importOPML(_ opmlFile: URL, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
guard !delegate.isOPMLImportInProgress else {
|
||||
completion(.failure(AccountError.opmlImportInProgress))
|
||||
|
|
|
@ -289,21 +289,18 @@ import Secrets
|
|||
}
|
||||
}
|
||||
|
||||
public func syncArticleStatusAll(completion: (() -> Void)? = nil) {
|
||||
let group = DispatchGroup()
|
||||
|
||||
activeAccounts.forEach {
|
||||
group.enter()
|
||||
$0.syncArticleStatus() { _ in
|
||||
group.leave()
|
||||
public func syncArticleStatusAll() async {
|
||||
|
||||
await withTaskGroup(of: Void.self) { taskGroup in
|
||||
|
||||
for account in activeAccounts {
|
||||
taskGroup.addTask {
|
||||
try? await account.syncArticleStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
group.notify(queue: DispatchQueue.global(qos: .background)) {
|
||||
completion?()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func saveAll() {
|
||||
accounts.forEach { $0.save() }
|
||||
}
|
||||
|
|
|
@ -68,8 +68,8 @@ import Account
|
|||
lastTimedRefresh = Date()
|
||||
update()
|
||||
|
||||
AccountManager.shared.syncArticleStatusAll()
|
||||
|
||||
Task { @MainActor in
|
||||
await AccountManager.shared.syncArticleStatusAll()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -187,7 +187,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|||
if Date() > lastRefresh.addingTimeInterval(15 * 60) {
|
||||
accountManager.refreshAll(errorHandler: ErrorHandler.log)
|
||||
} else {
|
||||
accountManager.syncArticleStatusAll()
|
||||
Task { @MainActor in
|
||||
await accountManager.syncArticleStatusAll()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
accountManager.refreshAll(errorHandler: ErrorHandler.log)
|
||||
|
@ -331,9 +333,8 @@ private extension AppDelegate {
|
|||
}
|
||||
|
||||
Task { @MainActor in
|
||||
self.accountManager.syncArticleStatusAll() {
|
||||
completeProcessing()
|
||||
}
|
||||
await self.accountManager.syncArticleStatusAll()
|
||||
completeProcessing()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue