mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-01-09 08:23:42 +01:00
Convert delete(subscriptionID) to async await.
This commit is contained in:
parent
0963abdb8e
commit
24c8bdcc1a
@ -823,48 +823,21 @@ public protocol CloudKitZone: AnyObject {
|
||||
/// Delete a CKSubscription
|
||||
func delete(subscriptionID: String) async throws {
|
||||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
self.delete(subscriptionID: subscriptionID) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume()
|
||||
case .failure(let error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
guard let database else { throw CloudKitZoneError.unknown }
|
||||
|
||||
/// Delete a CKSubscription
|
||||
func delete(subscriptionID: String, completion: @escaping @Sendable (Result<Void, Error>) -> Void) {
|
||||
do {
|
||||
_ = try await database.deleteSubscription(withID: subscriptionID)
|
||||
} catch {
|
||||
|
||||
guard let database else {
|
||||
completion(.failure(CloudKitZoneError.unknown))
|
||||
return
|
||||
}
|
||||
switch CloudKitZoneResult.resolve(error) {
|
||||
|
||||
database.delete(withSubscriptionID: subscriptionID) { [weak self] _, error in
|
||||
case .retry(let timeToWait):
|
||||
os_log(.error, log: self.log, "%@ zone delete subscription retry in %f seconds.", self.zoneID.zoneName, timeToWait)
|
||||
await self.delay(for: timeToWait)
|
||||
try await delete(subscriptionID: subscriptionID)
|
||||
|
||||
guard let self else {
|
||||
completion(.failure(CloudKitZoneError.unknown))
|
||||
return
|
||||
}
|
||||
|
||||
Task { @MainActor in
|
||||
|
||||
switch CloudKitZoneResult.resolve(error) {
|
||||
|
||||
case .success:
|
||||
completion(.success(()))
|
||||
|
||||
case .retry(let timeToWait):
|
||||
os_log(.error, log: self.log, "%@ zone delete subscription retry in %f seconds.", self.zoneID.zoneName, timeToWait)
|
||||
await self.delay(for: timeToWait)
|
||||
self.delete(subscriptionID: subscriptionID, completion: completion)
|
||||
|
||||
default:
|
||||
completion(.failure(CloudKitError(error!)))
|
||||
}
|
||||
default:
|
||||
throw CloudKitError(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user