@@ -6,12 +6,12 @@ import Ably
66/// This provides us with a mockable interface to ably-cocoa, and it also allows internal components and their tests not to need to worry about some of the boring details of how we bridge Swift types to `_AblyPluginSupportPrivate`'s Objective-C API (i.e. boxing).
77internal protocol CoreSDK : AnyObject , Sendable {
88 /// Implements the internal `#publish` method of RTO15.
9- func publish ( objectMessages: [ OutboundObjectMessage ] ) async throws ( ARTErrorInfo)
9+ func nosync_publish ( objectMessages: [ OutboundObjectMessage ] , callback : @escaping @ Sendable ( Result < Void , ARTErrorInfo > ) -> Void )
1010
1111 /// Implements the server time fetch of RTO16, including the storing and usage of the local clock offset.
12- func fetchServerTime ( ) async throws ( ARTErrorInfo) -> Date
12+ func nosync_fetchServerTime ( callback : @escaping @ Sendable ( Result < Date , ARTErrorInfo > ) -> Void )
1313
14- /// Replaces the implementation of ``publish (objectMessages:)``.
14+ /// Replaces the implementation of ``nosync_publish (objectMessages:callback :)``.
1515 ///
1616 /// Used by integration tests, for example to disable `ObjectMessage` publishing so that a test can verify that a behaviour is not a side effect of an `ObjectMessage` sent by the SDK.
1717 func testsOnly_overridePublish( with newImplementation: @escaping ( [ OutboundObjectMessage ] ) async throws ( ARTErrorInfo) -> Void )
@@ -29,7 +29,7 @@ internal final class DefaultCoreSDK: CoreSDK {
2929 private let pluginAPI : PluginAPIProtocol
3030 private let logger : Logger
3131
32- /// If set to true , ``publish(objectMessages:)`` will behave like a no-op .
32+ /// If set, ``publish(objectMessages:)`` delegates to this implementation .
3333 ///
3434 /// This enables the `testsOnly_overridePublish(with:)` test hook.
3535 ///
@@ -50,31 +50,36 @@ internal final class DefaultCoreSDK: CoreSDK {
5050
5151 // MARK: - CoreSDK conformance
5252
53- internal func publish ( objectMessages: [ OutboundObjectMessage ] ) async throws ( ARTErrorInfo) {
54- logger. log ( " publish (objectMessages: \( LoggingUtilities . formatObjectMessagesForLogging ( objectMessages) ) ) " , level: . debug)
53+ internal func nosync_publish ( objectMessages: [ OutboundObjectMessage ] , callback : @escaping @ Sendable ( Result < Void , ARTErrorInfo > ) -> Void ) {
54+ logger. log ( " nosync_publish (objectMessages: \( LoggingUtilities . formatObjectMessagesForLogging ( objectMessages) ) ) " , level: . debug)
5555
5656 // Use the overridden implementation if supplied
5757 let overriddenImplementation = mutex. withLock {
5858 overriddenPublishImplementation
5959 }
6060 if let overriddenImplementation {
61- do {
62- try await overriddenImplementation ( objectMessages)
63- } catch {
64- guard let artErrorInfo = error as? ARTErrorInfo else {
65- preconditionFailure ( " Expected ARTErrorInfo, got \( error) " )
61+ let queue = pluginAPI. internalQueue ( for: client)
62+ Task {
63+ do {
64+ try await overriddenImplementation ( objectMessages)
65+ queue. async { callback ( . success( ( ) ) ) }
66+ } catch {
67+ guard let artErrorInfo = error as? ARTErrorInfo else {
68+ preconditionFailure ( " Expected ARTErrorInfo, got \( error) " )
69+ }
70+ queue. async { callback ( . failure( artErrorInfo) ) }
6671 }
67- throw artErrorInfo
6872 }
6973 return
7074 }
7175
7276 // TODO: Implement message size checking (https://github.com/ably/ably-liveobjects-swift-plugin/issues/13)
73- try await DefaultInternalPlugin . sendObject (
77+ DefaultInternalPlugin . nosync_sendObject (
7478 objectMessages: objectMessages,
7579 channel: channel,
7680 client: client,
7781 pluginAPI: pluginAPI,
82+ callback: callback,
7883 )
7984 }
8085
@@ -84,26 +89,21 @@ internal final class DefaultCoreSDK: CoreSDK {
8489 }
8590 }
8691
87- internal func fetchServerTime( ) async throws ( ARTErrorInfo) -> Date {
88- try await withCheckedContinuation { ( continuation: CheckedContinuation < Result < Date , ARTErrorInfo > , _ > ) in
89- let internalQueue = pluginAPI. internalQueue ( for: client)
90-
91- internalQueue. async { [ client, pluginAPI] in
92- pluginAPI. nosync_fetchServerTime ( for: client) { serverTime, error in
93- // We don't currently rely on this documented behaviour of `noSync_fetchServerTime` but we may do later, so assert it to be sure it's happening.
94- dispatchPrecondition ( condition: . onQueue( internalQueue) )
95-
96- if let error {
97- continuation. resume ( returning: . failure( ARTErrorInfo . castPluginPublicErrorInfo ( error) ) )
98- } else {
99- guard let serverTime else {
100- preconditionFailure ( " nosync_fetchServerTime gave nil serverTime and nil error " )
101- }
102- continuation. resume ( returning: . success( serverTime) )
103- }
92+ internal func nosync_fetchServerTime( callback: @escaping @Sendable ( Result < Date , ARTErrorInfo > ) -> Void ) {
93+ let internalQueue = pluginAPI. internalQueue ( for: client)
94+
95+ pluginAPI. nosync_fetchServerTime ( for: client) { serverTime, error in
96+ dispatchPrecondition ( condition: . onQueue( internalQueue) )
97+
98+ if let error {
99+ callback ( . failure( ARTErrorInfo . castPluginPublicErrorInfo ( error) ) )
100+ } else {
101+ guard let serverTime else {
102+ preconditionFailure ( " nosync_fetchServerTime gave nil serverTime and nil error " )
104103 }
104+ callback ( . success( serverTime) )
105105 }
106- } . get ( )
106+ }
107107 }
108108
109109 internal var nosync_channelState : _AblyPluginSupportPrivate . RealtimeChannelState {
0 commit comments