forked from ably/ably-chat-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ECO-4936] Implement the ability to attach and detach a room #8
Closed
ruancomelli
wants to merge
2
commits into
base-sha/0e9f7035bbbfb7b2d8f8deaa5bad6b4f64174b38
from
head-sha/09e54f6029ff17abfa8d3fd90689432e8b4f1bbc/2024-09-26T09-37-10/75fff1
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
Sources/AblyChat/AblyCocoaExtensions/Ably+Concurrency.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Ably | ||
|
||
// This file contains extensions to ably-cocoa’s types, to make them easier to use in Swift concurrency. | ||
// 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 | ||
attach { error in | ||
if let error { | ||
continuation.resume(throwing: error) | ||
} else { | ||
continuation.resume() | ||
} | ||
} | ||
} | ||
} | ||
|
||
func detachAsync() async throws { | ||
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, _>) in | ||
detach { error in | ||
if let error { | ||
continuation.resume(throwing: error) | ||
} else { | ||
continuation.resume() | ||
} | ||
} | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Sources/AblyChat/AblyCocoaExtensions/Ably+Dependencies.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Ably | ||
|
||
// TODO: remove "@unchecked Sendable" once https://github.com/ably/ably-cocoa/issues/1962 done | ||
|
||
#if swift(>=6) | ||
// This @retroactive is needed to silence the Swift 6 compiler error "extension declares a conformance of imported type 'ARTRealtimeChannels' to imported protocol 'Sendable'; this will not behave correctly if the owners of 'Ably' introduce this conformance in the future (…) add '@retroactive' to silence this warning". I don’t fully understand the implications of this but don’t really mind since both libraries are in our control. | ||
extension ARTRealtime: RealtimeClientProtocol, @retroactive @unchecked Sendable {} | ||
|
||
extension ARTRealtimeChannels: RealtimeChannelsProtocol, @retroactive @unchecked Sendable {} | ||
|
||
extension ARTRealtimeChannel: RealtimeChannelProtocol, @retroactive @unchecked Sendable {} | ||
#else | ||
extension ARTRealtime: RealtimeClientProtocol, @unchecked Sendable {} | ||
|
||
extension ARTRealtimeChannels: RealtimeChannelsProtocol, @unchecked Sendable {} | ||
|
||
extension ARTRealtimeChannel: RealtimeChannelProtocol, @unchecked Sendable {} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Ably | ||
|
||
/// Expresses the requirements of the Ably realtime client that is supplied to the Chat SDK. | ||
/// | ||
/// The `ARTRealtime` class from the ably-cocoa SDK implements this protocol. | ||
public protocol RealtimeClientProtocol: ARTRealtimeProtocol, Sendable { | ||
associatedtype Channels: RealtimeChannelsProtocol | ||
|
||
// It’s not clear to me why ARTRealtimeProtocol doesn’t include this property. I briefly tried adding it but ran into compilation failures that it wasn’t immediately obvious how to fix. | ||
var channels: Channels { get } | ||
} | ||
|
||
/// Expresses the requirements of the object returned by ``RealtimeClientProtocol.channels``. | ||
public protocol RealtimeChannelsProtocol: ARTRealtimeChannelsProtocol, Sendable { | ||
associatedtype Channel: RealtimeChannelProtocol | ||
|
||
// It’s not clear to me why ARTRealtimeChannelsProtocol doesn’t include this property (https://github.com/ably/ably-cocoa/issues/1968). | ||
func get(_ name: String) -> Channel | ||
} | ||
|
||
/// Expresses the requirements of the object returned by ``RealtimeChannelsProtocol.get(_:)``. | ||
public protocol RealtimeChannelProtocol: ARTRealtimeChannelProtocol, Sendable {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider implementing error aggregation in attach() and detach() methods
The current implementation stops at the first error. It might be beneficial to attempt all operations and then report all errors, if any. This would provide a more complete picture of what went wrong and allow for better error handling and reporting.