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
Based on [1] at c3a4917. Implementation and tests are Claude-generated
from the spec; I've largely resisted the temptation to tweak things that
aren't quite how I'd write them but which are still correct.
The only behaviour here that's not in the spec is to also apply-on-ACK
for batch operations (the batch API isn't in the spec yet).
TODO:
- test for batch
[1] ably/specification#419
* If the underlying instance at runtime is not a map, this method throws an error.
841
841
*
842
-
* This does not modify the underlying data of the map. Instead, the change is applied when
843
-
* the published operation is echoed back to the client and applied to the object.
844
-
* To get notified when object gets updated, use {@linkPathObjectBase.subscribe | PathObject.subscribe} or {@link InstanceBase.subscribe | Instance.subscribe}, as appropriate.
842
+
* This does not modify the underlying data of the map. Instead, when the batch function returns, the
843
+
* batched operations are sent to Ably. Once accepted, they are applied locally before the
844
+
* promise returned by {@linkBatchOperations.batch | batch()} resolves.
* If the underlying instance at runtime is not a map, this method throws an error.
857
857
*
858
-
* This does not modify the underlying data of the map. Instead, the change is applied when
859
-
* the published operation is echoed back to the client and applied to the object.
860
-
* To get notified when object gets updated, use {@linkPathObjectBase.subscribe | PathObject.subscribe} or {@link InstanceBase.subscribe | Instance.subscribe}, as appropriate.
858
+
* This does not modify the underlying data of the map. Instead, when the batch function returns, the
859
+
* batched operations are sent to Ably. Once accepted, they are applied locally before the
860
+
* promise returned by {@linkBatchOperations.batch | batch()} resolves.
* If the underlying instance at runtime is not a counter, this method throws an error.
877
877
*
878
-
* This does not modify the underlying data of the counter. Instead, the change is applied when
879
-
* the published operation is echoed back to the client and applied to the object.
880
-
* To get notified when object gets updated, use {@linkPathObjectBase.subscribe | PathObject.subscribe} or {@link InstanceBase.subscribe | Instance.subscribe}, as appropriate.
878
+
* This does not modify the underlying data of the counter. Instead, when the batch function returns, the
879
+
* batched operations are sent to Ably. Once accepted, they are applied locally before the
880
+
* promise returned by {@linkBatchOperations.batch | batch()} resolves.
881
881
*
882
882
* @param amount - The amount by which to increase the counter value. If not provided, defaults to 1.
* If the underlying instance at runtime is not a map, this method throws an error.
906
906
*
907
-
* This does not modify the underlying data of the map. Instead, the change is applied when
908
-
* the published operation is echoed back to the client and applied to the object.
909
-
* To get notified when object gets updated, use {@linkPathObjectBase.subscribe | PathObject.subscribe} or {@link InstanceBase.subscribe | Instance.subscribe}, as appropriate.
907
+
* This does not modify the underlying data of the map. Instead, when the batch function returns, the
908
+
* batched operations are sent to Ably. Once accepted, they are applied locally before the
909
+
* promise returned by {@linkBatchOperations.batch | batch()} resolves.
* If the underlying instance at runtime is not a map, this method throws an error.
922
922
*
923
-
* This does not modify the underlying data of the map. Instead, the change is applied when
924
-
* the published operation is echoed back to the client and applied to the object.
925
-
* To get notified when object gets updated, use {@linkPathObjectBase.subscribe | PathObject.subscribe} or {@link InstanceBase.subscribe | Instance.subscribe}, as appropriate.
923
+
* This does not modify the underlying data of the map. Instead, when the batch function returns, the
924
+
* batched operations are sent to Ably. Once accepted, they are applied locally before the
925
+
* promise returned by {@linkBatchOperations.batch | batch()} resolves.
* If the underlying instance at runtime is not a counter, this method throws an error.
939
939
*
940
-
* This does not modify the underlying data of the counter. Instead, the change is applied when
941
-
* the published operation is echoed back to the client and applied to the object.
942
-
* To get notified when object gets updated, use {@linkPathObjectBase.subscribe | PathObject.subscribe} or {@link InstanceBase.subscribe | Instance.subscribe}, as appropriate.
940
+
* This does not modify the underlying data of the counter. Instead, when the batch function returns, the
941
+
* batched operations are sent to Ably. Once accepted, they are applied locally before the
942
+
* promise returned by {@linkBatchOperations.batch | batch()} resolves.
943
943
*
944
944
* @param amount - The amount by which to increase the counter value. If not provided, defaults to 1.
* Batching enables you to group multiple operations together and send them to the Ably service in a single channel message.
968
968
* As a result, other clients will receive the changes in a single channel message once the batch function has completed.
969
969
*
970
-
* The objects' data is not modified inside the batch function. Instead, the objects will be updated
971
-
* when the batched operations are applied by the Ably service and echoed back to the client.
970
+
* The objects' data is not modified inside the batch function. The batched operations are sent to Ably
971
+
* and, once accepted, applied locally. The returned promise resolves after all operations have been applied.
972
972
*
973
973
* @param fn - A synchronous function that receives a {@link BatchContext} used to group operations together.
974
-
* @returns A promise which resolves upon success of the batch operation and rejects with an {@link ErrorInfo} object upon its failure.
974
+
* @returns A promise which resolves after all batched operations have been accepted by Ably and applied locally, or rejects with an {@link ErrorInfo} object upon failure.
* or if called via {@link LiveMapPathObject} and the map instance at the specified path cannot
990
990
* be resolved at the time of the call, this method throws an error.
991
991
*
992
-
* This does not modify the underlying data of the map. Instead, the change is applied when
993
-
* the published operation is echoed back to the client and applied to the object.
994
-
* To get notified when object gets updated, use {@link PathObjectBase.subscribe | PathObject.subscribe} or {@link InstanceBase.subscribe | Instance.subscribe}, as appropriate.
992
+
* The operation is sent to Ably and, once accepted, applied locally. The returned promise resolves
993
+
* after the operation has been applied.
995
994
*
996
995
* @param key - The key to set the value for.
997
996
* @param value - The value to assign to the key.
998
-
* @returns A promise which resolves upon success of the operation and rejects with an {@link ErrorInfo} object upon its failure.
997
+
* @returns A promise which resolves after the operation has been accepted by Ably and applied locally, or rejects with an {@link ErrorInfo} object upon failure.
* or if called via {@link LiveMapPathObject} and the map instance at the specified path cannot
1008
1007
* be resolved at the time of the call, this method throws an error.
1009
1008
*
1010
-
* This does not modify the underlying data of the map. Instead, the change is applied when
1011
-
* the published operation is echoed back to the client and applied to the object.
1012
-
* To get notified when object gets updated, use {@link PathObjectBase.subscribe | PathObject.subscribe} or {@link InstanceBase.subscribe | Instance.subscribe}, as appropriate.
1009
+
* The operation is sent to Ably and, once accepted, applied locally. The returned promise resolves
1010
+
* after the operation has been applied.
1013
1011
*
1014
1012
* @param key - The key to remove.
1015
-
* @returns A promise which resolves upon success of the operation and rejects with an {@link ErrorInfo} object upon its failure.
1013
+
* @returns A promise which resolves after the operation has been accepted by Ably and applied locally, or rejects with an {@link ErrorInfo} object upon failure.
* or if called via {@link LiveCounterPathObject} and the counter instance at the specified path cannot
1030
1028
* be resolved at the time of the call, this method throws an error.
1031
1029
*
1032
-
* This does not modify the underlying data of the counter. Instead, the change is applied when
1033
-
* the published operation is echoed back to the client and applied to the object.
1034
-
* To get notified when object gets updated, use {@link PathObjectBase.subscribe | PathObject.subscribe} or {@link InstanceBase.subscribe | Instance.subscribe}, as appropriate.
1030
+
* The operation is sent to Ably and, once accepted, applied locally. The returned promise resolves
1031
+
* after the operation has been applied.
1035
1032
*
1036
1033
* @param amount - The amount by which to increase the counter value. If not provided, defaults to 1.
1037
-
* @returns A promise which resolves upon success of the operation and rejects with an {@link ErrorInfo} object upon its failure.
1034
+
* @returns A promise which resolves after the operation has been accepted by Ably and applied locally, or rejects with an {@link ErrorInfo} object upon failure.
1038
1035
*/
1039
1036
increment(amount?: number): Promise<void>;
1040
1037
1041
1038
/**
1042
1039
* An alias for calling {@link LiveCounterOperations.increment | increment(-amount)}
1043
1040
*
1044
1041
* @param amount - The amount by which to decrease the counter value. If not provided, defaults to 1.
1045
-
* @returns A promise which resolves upon success of the operation and rejects with an {@link ErrorInfo} object upon its failure.
1042
+
* @returns A promise which resolves after the operation has been accepted by Ably and applied locally, or rejects with an {@link ErrorInfo} object upon failure.
1046
1043
*/
1047
1044
decrement(amount?: number): Promise<void>;
1048
1045
}
@@ -1061,11 +1058,11 @@ interface AnyOperations {
1061
1058
* Batching enables you to group multiple operations together and send them to the Ably service in a single channel message.
1062
1059
* As a result, other clients will receive the changes in a single channel message once the batch function has completed.
1063
1060
*
1064
-
* The objects' data is not modified inside the batch function. Instead, the objects will be updated
1065
-
* when the batched operations are applied by the Ably service and echoed back to the client.
1061
+
* The objects' data is not modified inside the batch function. The batched operations are sent to Ably
1062
+
* and, once accepted, applied locally. The returned promise resolves after all operations have been applied.
1066
1063
*
1067
1064
* @param fn - A synchronous function that receives a {@link BatchContext} used to group operations together.
1068
-
* @returns A promise which resolves upon success of the batch operation and rejects with an {@link ErrorInfo} object upon its failure.
1065
+
* @returns A promise which resolves after all batched operations have been accepted by Ably and applied locally, or rejects with an {@link ErrorInfo} object upon failure.
* or if called via {@link AnyPathObject} and the map instance at the specified path cannot
1080
1077
* be resolved at the time of the call, this method throws an error.
1081
1078
*
1082
-
* This does not modify the underlying data of the map. Instead, the change is applied when
1083
-
* the published operation is echoed back to the client and applied to the object.
1084
-
* To get notified when object gets updated, use {@link PathObjectBase.subscribe | PathObject.subscribe} or {@link InstanceBase.subscribe | Instance.subscribe}, as appropriate.
1079
+
* The operation is sent to Ably and, once accepted, applied locally. The returned promise resolves
1080
+
* after the operation has been applied.
1085
1081
*
1086
1082
* @param key - The key to set the value for.
1087
1083
* @param value - The value to assign to the key.
1088
-
* @returns A promise which resolves upon success of the operation and rejects with an {@link ErrorInfo} object upon its failure.
1084
+
* @returns A promise which resolves after the operation has been accepted by Ably and applied locally, or rejects with an {@link ErrorInfo} object upon failure.
* or if called via {@link AnyPathObject} and the map instance at the specified path cannot
1098
1094
* be resolved at the time of the call, this method throws an error.
1099
1095
*
1100
-
* This does not modify the underlying data of the map. Instead, the change is applied when
1101
-
* the published operation is echoed back to the client and applied to the object.
1102
-
* To get notified when object gets updated, use {@link PathObjectBase.subscribe | PathObject.subscribe} or {@link InstanceBase.subscribe | Instance.subscribe}, as appropriate.
1096
+
* The operation is sent to Ably and, once accepted, applied locally. The returned promise resolves
1097
+
* after the operation has been applied.
1103
1098
*
1104
1099
* @param key - The key to remove.
1105
-
* @returns A promise which resolves upon success of the operation and rejects with an {@link ErrorInfo} object upon its failure.
1100
+
* @returns A promise which resolves after the operation has been accepted by Ably and applied locally, or rejects with an {@link ErrorInfo} object upon failure.
* or if called via {@link AnyPathObject} and the counter instance at the specified path cannot
1117
1112
* be resolved at the time of the call, this method throws an error.
1118
1113
*
1119
-
* This does not modify the underlying data of the counter. Instead, the change is applied when
1120
-
* the published operation is echoed back to the client and applied to the object.
1121
-
* To get notified when object gets updated, use {@link PathObjectBase.subscribe | PathObject.subscribe} or {@link InstanceBase.subscribe | Instance.subscribe}, as appropriate.
1114
+
* The operation is sent to Ably and, once accepted, applied locally. The returned promise resolves
1115
+
* after the operation has been applied.
1122
1116
*
1123
1117
* @param amount - The amount by which to increase the counter value. If not provided, defaults to 1.
1124
-
* @returns A promise which resolves upon success of the operation and rejects with an {@link ErrorInfo} object upon its failure.
1118
+
* @returns A promise which resolves after the operation has been accepted by Ably and applied locally, or rejects with an {@link ErrorInfo} object upon failure.
1125
1119
*/
1126
1120
increment(amount?: number): Promise<void>;
1127
1121
1128
1122
/**
1129
1123
* An alias for calling {@link AnyOperations.increment | increment(-amount)}
1130
1124
*
1131
1125
* @param amount - The amount by which to decrease the counter value. If not provided, defaults to 1.
1132
-
* @returns A promise which resolves upon success of the operation and rejects with an {@link ErrorInfo} object upon its failure.
1126
+
* @returns A promise which resolves after the operation has been accepted by Ably and applied locally, or rejects with an {@link ErrorInfo} object upon failure.
// Access to this method is synchronised by ConnectionManager#processChannelMessage, in order to synchronise access to the state stored in _decodingContext.
0 commit comments