You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In 392fae3 I tried to be clever and treat the subscription storage as
part of the mutable state (i.e. by making it a struct) but this got
complicated because it needs to be able to update itself later (when the
user unsubscribes), leading to a lot of unpleasant boilerplate.
Let's instead use the EventEmitter reference type copied from ably-swift
in 3df3687 and ac04f3c.
To limit the scope of the changes, I've tried to not change the
SubscriptionStorage type — which is now just a bridge between the
EventEmitter API and the public API — too much. I've also not changed
the public API, even though we have #28 which suggests updating the
"unsubscribing within a listener" public API to match that of the
aforementioned ably-swift EventEmitter (this API is still not final
there and I don't want to churn us over to using it yet).
Resolves#102.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
// TODO: Looking at this again later the whole process for adding a subscriber is really verbose and boilerplate-y, and I think the unfortunate result of me trying to be clever at some point; revisit in https://github.com/ably/ably-liveobjects-swift-plugin/issues/102
333
+
// TODO: make the RTO20 wait-for-synced use this mechanism (https://github.com/ably/ably-liveobjects-swift-plugin/issues/120)
342
334
mutableStateMutex.withSync{ mutableState in
343
-
// swiftlint:disable:next trailing_closure
344
-
mutableState.onInternal(event: event, callback: callback, updateSelfLater:{[weak self] action in
/// Used when the object wishes to subscribe to its own events (i.e. unaffected by `offAll()`); used e.g. to wait for a sync before returning from `getRoot()`, per RTO1c.
/// Has the same cases as `ObjectsSyncState` but with associated data to store the sync sequence data and represent the constraint that you only have a sync sequence if you're SYNCING.
682
676
internalenumState{
683
677
case initialized
@@ -726,7 +720,7 @@ internal final class InternalDefaultRealtimeObjects: Sendable, InternalRealtimeO
726
720
return
727
721
}
728
722
// RTO17b
729
-
emitObjectsEvent(event, on: userCallbackQueue)
723
+
nosync_emitObjectsEvent(event, on: userCallbackQueue)
730
724
}
731
725
732
726
internalmutatingfunc nosync_onChannelAttached(
@@ -1018,45 +1012,28 @@ internal final class InternalDefaultRealtimeObjects: Sendable, InternalRealtimeO
// TODO: Looking at this again later the whole process for adding a subscriber is really verbose and boilerplate-y, and I think the unfortunate result of me trying to be clever at some point; revisit in https://github.com/ably/ably-liveobjects-swift-plugin/issues/102. Also as things stand we end up not being able to use this method because we run into Swift exclusivity violations when we try to unsubscribe from within a listener that's invoked when the mutable state mutex is already held (see https://github.com/ably/ably-liveobjects-swift-plugin/issues/120), so e.g. the RTO20 wait-for-synced can't use this mechanism, which it should be able to.
1047
-
letupdateSubscriptionStorage:SubscriptionStorage<ObjectsEvent,Void>.UpdateSubscriptionStorage={ action in
0 commit comments