Convert createStatusesIfNeeded to async await.
This commit is contained in:
parent
1824c15ddc
commit
e523e06efe
|
@ -880,22 +880,14 @@ public enum FetchType {
|
|||
/// Make sure statuses exist. Any existing statuses won’t be touched.
|
||||
/// All created statuses will be marked as read and not starred.
|
||||
/// Sends a .StatusesDidChange notification.
|
||||
func createStatusesIfNeeded(articleIDs: Set<String>, completion: DatabaseCompletionBlock? = nil) {
|
||||
guard !articleIDs.isEmpty else {
|
||||
completion?(nil)
|
||||
return
|
||||
}
|
||||
database.createStatusesIfNeeded(articleIDs: articleIDs) { error in
|
||||
func createStatusesIfNeeded(articleIDs: Set<String>) async throws {
|
||||
|
||||
MainActor.assumeIsolated {
|
||||
if let error = error {
|
||||
completion?(error)
|
||||
guard !articleIDs.isEmpty else {
|
||||
return
|
||||
}
|
||||
self.noteStatusesForArticleIDsDidChange(articleIDs)
|
||||
completion?(nil)
|
||||
}
|
||||
}
|
||||
|
||||
try await database.createStatusesIfNeeded(articleIDs: articleIDs)
|
||||
noteStatusesForArticleIDsDidChange(articleIDs)
|
||||
}
|
||||
|
||||
/// Mark articleIDs statuses based on statusKey and flag.
|
||||
|
|
|
@ -50,24 +50,23 @@ class FeedlyIngestStreamArticleIdsOperation: FeedlyOperation {
|
|||
}
|
||||
|
||||
switch result {
|
||||
case .success(let streamIds):
|
||||
account.createStatusesIfNeeded(articleIDs: Set(streamIds.ids)) { databaseError in
|
||||
case .success(let streamIDs):
|
||||
|
||||
MainActor.assumeIsolated {
|
||||
if let error = databaseError {
|
||||
self.didFinish(with: error)
|
||||
return
|
||||
}
|
||||
Task { @MainActor in
|
||||
do {
|
||||
try await account.createStatusesIfNeeded(articleIDs: Set(streamIDs.ids))
|
||||
|
||||
guard let continuation = streamIds.continuation else {
|
||||
guard let continuation = streamIDs.continuation else {
|
||||
os_log(.debug, log: self.log, "Reached end of stream for %@", self.resource.id)
|
||||
self.didFinish()
|
||||
return
|
||||
}
|
||||
|
||||
self.getStreamIds(continuation)
|
||||
} catch {
|
||||
self.didFinish(with: error)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
case .failure(let error):
|
||||
didFinish(with: error)
|
||||
|
|
|
@ -95,20 +95,6 @@ public extension ArticlesDatabase {
|
|||
}
|
||||
}
|
||||
|
||||
/// Create statuses for specified articleIDs. For existing statuses, don’t do anything.
|
||||
/// For newly-created statuses, mark them as read and not-starred.
|
||||
nonisolated func createStatusesIfNeeded(articleIDs: Set<String>, completion: @escaping DatabaseCompletionBlock) {
|
||||
|
||||
Task {
|
||||
do {
|
||||
try await createStatusesIfNeeded(articleIDs: articleIDs)
|
||||
callDatabaseCompletion(completion)
|
||||
} catch {
|
||||
callDatabaseCompletion(completion, .suspended)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nonisolated private func callUpdateArticlesCompletion(_ completion: @escaping UpdateArticlesCompletionBlock, _ result: UpdateArticlesResult) {
|
||||
|
||||
Task { @MainActor in
|
||||
|
|
Loading…
Reference in New Issue