Convert restoreFeed to async/await.

This commit is contained in:
Brent Simmons 2024-03-27 17:18:17 -07:00
parent 934a8c89fa
commit a7ba7e3b4a
9 changed files with 100 additions and 30 deletions

View File

@ -635,11 +635,13 @@ public enum FetchType {
delegate.renameFeed(for: self, with: feed, to: name, completion: completion)
}
public func restoreFeed(_ feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
delegate.restoreFeed(for: self, feed: feed, container: container, completion: completion)
public func restoreFeed(_ feed: Feed, container: Container) async throws {
try await delegate.restoreFeed(for: self, feed: feed, container: container)
}
public func addFolder(_ name: String) async throws -> Folder {
try await delegate.createFolder(for: self, name: name)
}

View File

@ -42,7 +42,7 @@ import Secrets
func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result<Void, Error>) -> Void)
func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result<Void, Error>) -> Void)
func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> Void)
func restoreFeed(for account: Account, feed: Feed, container: Container) async throws
func restoreFolder(for account: Account, folder: Folder) async throws
func markArticles(for account: Account, articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) async throws

View File

@ -321,17 +321,21 @@ enum CloudKitAccountDelegateError: LocalizedError {
}
}
func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
createFeed(for: account, url: feed.url, name: feed.editedName, container: container, validateFeed: true) { result in
switch result {
case .success:
completion(.success(()))
case .failure(let error):
completion(.failure(error))
func restoreFeed(for account: Account, feed: Feed, container: any Container) async throws {
try await withCheckedThrowingContinuation { continuation in
self.createFeed(for: account, url: feed.url, name: feed.editedName, container: container, validateFeed: true) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
func createFolder(for account: Account, name: String) async throws -> Folder {
try await withCheckedThrowingContinuation { continuation in
@ -471,17 +475,15 @@ enum CloudKitAccountDelegateError: LocalizedError {
folder.topLevelFeeds.remove(feed)
group.enter()
self.restoreFeed(for: account, feed: feed, container: folder) { result in
self.refreshProgress.completeTask()
group.leave()
switch result {
case .success:
break
case .failure(let error):
Task { @MainActor in
do {
try await self.restoreFeed(for: account, feed: feed, container: folder)
} catch {
os_log(.error, log: self.log, "Restore folder feed error: %@.", error.localizedDescription)
}
group.leave()
}
}
group.notify(queue: DispatchQueue.main) {

View File

@ -551,7 +551,22 @@ final class FeedbinAccountDelegate: AccountDelegate {
}
func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
func restoreFeed(for account: Account, feed: Feed, container: any Container) async throws {
try await withCheckedThrowingContinuation { continuation in
self.restoreFeed(for: account, feed: feed, container: container) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
private func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
if let existingFeed = account.existingFeed(withURL: feed.url) {
account.addFeed(existingFeed, to: container) { result in

View File

@ -533,7 +533,22 @@ final class FeedlyAccountDelegate: AccountDelegate {
to.addFeed(feed)
}
@MainActor func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
func restoreFeed(for account: Account, feed: Feed, container: any Container) async throws {
try await withCheckedThrowingContinuation { continuation in
self.restoreFeed(for: account, feed: feed, container: container) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
private func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
if let existingFeed = account.existingFeed(withURL: feed.url) {
account.addFeed(existingFeed, to: container) { result in
switch result {

View File

@ -112,11 +112,11 @@ final class LocalAccountDelegate: AccountDelegate {
completion(.success(()))
}
func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
func restoreFeed(for account: Account, feed: Feed, container: any Container) async throws {
container.addFeed(feed)
completion(.success(()))
}
func createFolder(for account: Account, name: String) async throws -> Folder {
guard let folder = account.ensureFolder(with: name) else {

View File

@ -581,7 +581,22 @@ final class NewsBlurAccountDelegate: AccountDelegate {
}
}
func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> ()) {
func restoreFeed(for account: Account, feed: Feed, container: any Container) async throws {
try await withCheckedThrowingContinuation { continuation in
self.restoreFeed(for: account, feed: feed, container: container) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
private func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> ()) {
if let existingFeed = account.existingFeed(withURL: feed.url) {
account.addFeed(existingFeed, to: container) { result in
switch result {

View File

@ -603,7 +603,22 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
}
}
func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
func restoreFeed(for account: Account, feed: Feed, container: any Container) async throws {
try await withCheckedThrowingContinuation { continuation in
self.restoreFeed(for: account, feed: feed, container: container) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
private func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result<Void, Error>) -> Void) {
if let existingFeed = account.existingFeed(withURL: feed.url) {
account.addFeed(existingFeed, to: container) { result in

View File

@ -187,11 +187,17 @@ import Core
}
BatchUpdate.shared.start()
account.restoreFeed(feed, container: container) { result in
BatchUpdate.shared.end()
self.checkResult(result)
}
Task { @MainActor in
do {
try await account.restoreFeed(feed, container: container)
BatchUpdate.shared.end()
} catch {
BatchUpdate.shared.end()
self.errorHandler(error)
}
}
}
private func restoreFolder() {