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
Maintain same root object when resetting the ObjectsPool
The correct behaviour wasn't clear from the spec when I wrote cb427d8,
but new spec PR [1] makes it seem that this is the right thing to do
(still needs clarifying though).
[1] ably/specification#346
Copy file name to clipboardExpand all lines: Sources/AblyLiveObjects/Internal/DefaultLiveMap.swift
+13Lines changed: 13 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -287,6 +287,13 @@ internal final class InternalDefaultLiveMap: Sendable {
287
287
}
288
288
}
289
289
290
+
/// Resets the map's data, per RTO4b2. This is to be used when an `ATTACHED` ProtocolMessage indicates that the only object in a channel is an empty root map.
291
+
internalfunc resetData(){
292
+
mutex.withLock{
293
+
mutableState.resetData()
294
+
}
295
+
}
296
+
290
297
// MARK: - Mutable state and the operations that affect it
291
298
292
299
privatestructMutableState{
@@ -544,6 +551,12 @@ internal final class InternalDefaultLiveMap: Sendable {
544
551
logger: logger,
545
552
)
546
553
}
554
+
555
+
/// Resets the map's data, per RTO4b2. This is to be used when an `ATTACHED` ProtocolMessage indicates that the only object in a channel is an empty root map.
logger.log("applySyncObjectsPool completed. Pool now contains \(entries.count) objects", level:.debug)
211
211
}
212
+
213
+
/// Removes all entries except the root, and clears the root's data. This is to be used when an `ATTACHED` ProtocolMessage indicates that the only object in a channel is an empty root map, per RTO4b.
214
+
internalmutatingfunc reset(){
215
+
letroot= root
216
+
217
+
// RTO4b1
218
+
entries =[Self.rootKey:.map(root)]
219
+
220
+
// RTO4b2
221
+
// TODO: this one is unclear (are we meant to replace the root or just clear its data?) https://github.com/ably/specification/pull/333/files#r2183493458. I believe that the answer is that we should just clear its data but the spec point needs to be clearer, see https://github.com/ably/specification/pull/346/files#r2201434895.
Copy file name to clipboardExpand all lines: Sources/AblyLiveObjects/InternalDefaultRealtimeObjects.swift
+1-2Lines changed: 1 addition & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -244,8 +244,7 @@ internal final class InternalDefaultRealtimeObjects: Sendable, LiveMapObjectPool
244
244
}
245
245
246
246
// RTO4b1, RTO4b2: Reset the ObjectsPool to have a single empty root object
247
-
// TODO: this one is unclear (are we meant to replace the root or just clear its data?) https://github.com/ably/specification/pull/333/files#r2183493458
248
-
objectsPool =.init(logger: logger)
247
+
objectsPool.reset()
249
248
250
249
// 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.
#expect(newPool.entries["map:existing@123"]==nil) // Should be removed
384
384
#expect(newPool.entries["counter:existing@456"]==nil) // Should be removed
385
385
386
-
// Verify root is a new zero-valued map (RTO4b2)
387
-
// TODO: this one is unclear (are we meant to replace the root or just clear its data?) https://github.com/ably/specification/pull/333/files#r2183493458
386
+
// Verify root is the same object, but with data cleared (RTO4b2)
387
+
// TODO: this one is unclear (are we meant to replace the root or just clear its data?) https://github.com/ably/specification/pull/333/files#r2183493458. I believe that the answer is that we should just clear its data but the spec point needs to be clearer, see https://github.com/ably/specification/pull/346/files#r2201434895.
388
388
letnewRoot= newPool.root
389
-
#expect(newRoot asAnyObject!== originalPool.root asAnyObject) // Should be a new instance
389
+
#expect(newRoot asAnyObject=== originalPool.root asAnyObject) // Should be same instance
390
390
#expect(newRoot.testsOnly_data.isEmpty) // Should be zero-valued (empty)
391
391
392
392
// RTO4b3, RTO4b4, RTO4b5: SyncObjectsPool must be cleared, sync sequence cleared, BufferedObjectOperations cleared
0 commit comments