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
// 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
279
+
mutableStateMutex.withSync{ mutableState in
280
+
// swiftlint:disable:next trailing_closure
281
+
mutableState.onInternal(event: event, callback: callback, updateSelfLater:{[weak self] action in
282
+
guardlet self else{
283
+
return
284
+
}
285
+
286
+
mutableStateMutex.withSync{ mutableState in
287
+
action(&mutableState)
288
+
}
289
+
})
290
+
}
291
+
}
292
+
286
293
internalfunc offAll(){
287
294
mutableStateMutex.withSync{ mutableState in
288
295
mutableState.offAll()
@@ -430,34 +437,45 @@ internal final class InternalDefaultRealtimeObjects: Sendable, LiveMapObjectsPoo
430
437
431
438
privatestructMutableState{
432
439
internalvarobjectsPool:ObjectsPool
433
-
/// Note that we only ever populate this during a multi-`ProtocolMessage` sync sequence. It is not used in the RTO4b or RTO5a5 cases where the sync data is entirely contained within a single ProtocolMessage, because an individual ProtocolMessage is processed atomically and so no other operations that might wish to query this property can occur concurrently with the handling of these cases.
/// 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.
/// The state that drives the emission of the `syncing` and `synced` events.
449
+
/// The state that drives the emission of the `syncing` and `synced` events and which stores the sync sequence data.
443
450
///
444
451
/// This manipulation of this value is based on https://github.com/ably/ably-js/blob/0c5baa9273ca87aec6ca594833d59c4c4d2dddbb/src/plugins/objects/objects.ts.
445
-
/// TODO: Bring in line with spec once it exists (https://github.com/ably/ably-liveobjects-swift-plugin/issues/80) and reconcile it with the existing state that we have
452
+
/// TODO: Bring in line with spec once it exists (https://github.com/ably/ably-liveobjects-swift-plugin/issues/80)
446
453
internalvarstate=State.initialized
447
454
448
-
/// The state that drives the emission of the `syncing` and `synced` events.
449
-
///
450
-
/// This type is copied from https://github.com/ably/ably-js/blob/0c5baa9273ca87aec6ca594833d59c4c4d2dddbb/src/plugins/objects/objects.ts.
451
-
/// TODO: Bring in line with spec once it exists (https://github.com/ably/ably-liveobjects-swift-plugin/issues/80)
455
+
/// 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.
452
456
internalenumState{
453
457
case initialized
454
-
case syncing
458
+
case syncing(AssociatedData.Syncing)
455
459
case synced
456
460
457
-
vartoEvent:ObjectsEvent?{
461
+
/// Note: We follow the same pattern as used in the WIP ably-swift: a state's associated data is a class instance and the convention is that to update the associated data for the current state you mutate the existing instance instead of creating a new one.
462
+
enumAssociatedData{
463
+
classSyncing{
464
+
/// Note that we only ever populate this during a multi-`ProtocolMessage` sync sequence. It is not used in the RTO4b or RTO5a5 cases where the sync data is entirely contained within a single ProtocolMessage, because an individual ProtocolMessage is processed atomically and so no other operations that might wish to query this property can occur concurrently with the handling of these cases.
465
+
///
466
+
/// It is optional because there are times that we transition to SYNCING even when the sync data is contained in a single ProtocolMessage (this behaviour is copied from JS and will be specified in https://github.com/ably/ably-liveobjects-swift-plugin/issues/80).
467
+
varsyncSequence:SyncSequence?
468
+
469
+
init(syncSequence:SyncSequence?){
470
+
self.syncSequence = syncSequence
471
+
}
472
+
}
473
+
}
474
+
475
+
vartoObjectsSyncState:ObjectsSyncState{
458
476
switchself{
459
477
case.initialized:
460
-
nil
478
+
.initialized
461
479
case.syncing:
462
480
.syncing
463
481
case.synced:
@@ -470,11 +488,11 @@ internal final class InternalDefaultRealtimeObjects: Sendable, LiveMapObjectsPoo
// We only care about the case where HAS_OBJECTS is not set (RTO4b); if it is set then we're going to shortly receive an OBJECT_SYNC instead (RTO4a)
@@ -505,9 +523,9 @@ internal final class InternalDefaultRealtimeObjects: Sendable, LiveMapObjectsPoo
505
523
// I have, for now, not directly implemented the "perform the actions for object sync completion" of RTO4b4 since my implementation doesn't quite match the model given there; here you only have a SyncObjectsPool if you have an OBJECT_SYNC in progress, which you might not have upon receiving an ATTACHED. Instead I've just implemented what seem like the relevant side effects. Can revisit this if "the actions for object sync completion" get more complex.
// 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
752
+
letupdateSubscriptionStorage:SubscriptionStorage<ObjectsEvent,Void>.UpdateSubscriptionStorage={ action in
/// The type that the spec uses to represent the client's state of syncing its local Objects data with the server.
2
+
///
3
+
/// (TODO: This isn't actually in the spec yet, will specify in https://github.com/ably/ably-liveobjects-swift-plugin/issues/80; it's currently copied from https://github.com/ably/ably-js/blob/0c5baa9273ca87aec6ca594833d59c4c4d2dddbb/src/plugins/objects/objects.ts)
0 commit comments