-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the ability to attach and detach a room
Based on the simplified requirements described in #19. This doesn’t include the emission of a room status change; will do that in a separate PR.
- Loading branch information
1 parent
0e9f703
commit 21da342
Showing
10 changed files
with
639 additions
and
12 deletions.
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, Swift.Error>) in | ||
attach { error in | ||
if let error { | ||
continuation.resume(throwing: error) | ||
} else { | ||
continuation.resume() | ||
} | ||
} | ||
} | ||
} | ||
|
||
func detachAsync() async throws { | ||
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Swift.Error>) 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
Oops, something went wrong.