Make async version of fetchArticles.

This commit is contained in:
Brent Simmons
2025-02-14 21:02:27 -08:00
parent fe801d85eb
commit 9476df8b05

View File

@@ -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<String>)
case search(String)
case searchWithArticleIDs(String, Set<String>)
@@ -671,6 +671,20 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
}
}
@MainActor public func fetchArticles(_ fetchType: FetchType) async throws -> Set<Article> {
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):