From 9476df8b05eae04ab54c2a923f459e5a84e563ea Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Fri, 14 Feb 2025 21:02:27 -0800 Subject: [PATCH] Make async version of fetchArticles. --- Modules/Account/Sources/Account/Account.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Modules/Account/Sources/Account/Account.swift b/Modules/Account/Sources/Account/Account.swift index 5a75ee1fb..16c3e334b 100644 --- a/Modules/Account/Sources/Account/Account.swift +++ b/Modules/Account/Sources/Account/Account.swift @@ -56,7 +56,7 @@ public enum FetchType { case unread(_: Int? = nil) case today(_: Int? = nil) case folder(Folder, Bool) - case feed(Feed) + case feed(Feed) // TODO: use feedID instead of Feed case articleIDs(Set) case search(String) case searchWithArticleIDs(String, Set) @@ -671,6 +671,20 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } } + @MainActor public func fetchArticles(_ fetchType: FetchType) async throws -> Set
{ + assert(Thread.isMainThread) + return try await withCheckedThrowingContinuation { continuation in + fetchArticlesAsync(fetchType) { articleSetResult in + switch articleSetResult { + case .success(let articles): + continuation.resume(returning: articles) + case .failure(let error): + continuation.resume(throwing: error) + } + } + } + } + public func fetchArticlesAsync(_ fetchType: FetchType, _ completion: @escaping ArticleSetResultBlock) { switch fetchType { case .starred(let limit):