Skip to content

Commit

Permalink
Add typed throws to attach / detach wrappers
Browse files Browse the repository at this point in the history
As far as I can tell, there’s no version of
withCheckedThrowingContinuation that uses typed throws, hence needing to
go via Result.
  • Loading branch information
lawrence-forooghian committed Nov 7, 2024
1 parent 0a51fcb commit 033c859
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions Sources/AblyChat/AblyCocoaExtensions/Ably+Concurrency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ import Ably
// TODO: remove once we improve this experience in ably-cocoa (https://github.com/ably/ably-cocoa/issues/1967)

internal extension ARTRealtimeChannelProtocol {
func attachAsync() async throws {
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, _>) in
func attachAsync() async throws(ARTErrorInfo) {
try await withCheckedContinuation { (continuation: CheckedContinuation<Result<Void, ARTErrorInfo>, _>) in
attach { error in
if let error {
continuation.resume(throwing: error)
continuation.resume(returning: .failure(error))
} else {
continuation.resume()
continuation.resume(returning: .success(()))
}
}
}
}.get()
}

func detachAsync() async throws {
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, _>) in
func detachAsync() async throws(ARTErrorInfo) {
try await withCheckedContinuation { (continuation: CheckedContinuation<Result<Void, ARTErrorInfo>, _>) in
detach { error in
if let error {
continuation.resume(throwing: error)
continuation.resume(returning: .failure(error))
} else {
continuation.resume()
continuation.resume(returning: .success(()))
}
}
}
}.get()
}
}

0 comments on commit 033c859

Please sign in to comment.