Continue converting ArticlesDatabase to async/await.

This commit is contained in:
Brent Simmons
2023-10-01 14:15:17 -07:00
parent ad6b00a6d5
commit 373d7ed98b
3 changed files with 20 additions and 8 deletions

View File

@@ -1239,7 +1239,19 @@ private extension Account {
}
func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set<String>, _ completion: @escaping ArticleSetResultBlock) {
database.fetchArticlesMatchingWithArticleIDsAsync(searchString, articleIDs, completion)
Task { @MainActor in
do {
let articles = try await database.articlesForSearchStringInArticleIDs(searchString, articleIDs)
Task { @MainActor in
completion(.success(articles))
}
} catch {
Task { @MainActor in
completion(.failure(error as! DatabaseError))
}
}
}
}
func fetchArticles(articleIDs: Set<String>) throws -> Set<Article> {

View File

@@ -161,13 +161,13 @@ public typealias ArticleStatusesResultBlock = (ArticleStatusesResult) -> Void
}
public func articlesForSearchStringInFeeds(_ searchString: String, _ feedIDs: Set<String>) async throws -> Set<Article> {
try await articlesTable.articleForSearchStringInFeeds(searchString, feedIDs)
try await articlesTable.articlesForSearchStringInFeeds(searchString, feedIDs)
}
public func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set<String>, _ completion: @escaping ArticleSetResultBlock) {
articlesTable.fetchArticlesMatchingWithArticleIDsAsync(searchString, articleIDs, completion)
public func articlesForSearchStringInArticleIDs(_ searchString: String, _ articleIDs: Set<String>) async throws -> Set<Article> {
try await articlesTable.articlesForSearchStringInArticleIDs(searchString, articleIDs)
}
// MARK: - Unread Counts
/// Fetch all non-zero unread counts.

View File

@@ -149,12 +149,12 @@ final class ArticlesTable: DatabaseTable {
return articles
}
func articleForSearchStringInFeeds(_ searchString: String, _ feedIDs: Set<String>) async throws -> Set<Article> {
func articlesForSearchStringInFeeds(_ searchString: String, _ feedIDs: Set<String>) async throws -> Set<Article> {
try await articlesWithFetchMethod { self.fetchArticlesMatching(searchString, feedIDs, $0) }
}
func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set<String>, _ completion: @escaping ArticleSetResultBlock) {
fetchArticlesAsync({ self.fetchArticlesMatchingWithArticleIDs(searchString, articleIDs, $0) }, completion)
func articlesForSearchStringInArticleIDs(_ searchString: String, _ articleIDs: Set<String>) async throws -> Set<Article> {
try await articlesWithFetchMethod { self.fetchArticlesMatchingWithArticleIDs(searchString, articleIDs, $0) }
}
// MARK: - Fetching Articles for Indexer