mutate Map Item
abstract suspend fun mutateMapItem(mapSidOrUniqueName: String, itemKey: String, mutator: suspend (<Error class: unknown class>?) -> <Error class: unknown class>?): SyncMap.Item
Mutate value of the SyncMap.Item without opening SyncMap using provided Mutator function.
The Mutator function could be invoked more than once in case of data collision, i.e. if data on backend is modified while the mutate operation is executing. It guarantees that Mutator generates new value based on latest item data.
Possible use case is to implement distributed counter:
@Serializable
data class Counter(val value: Long = 0) {
operator fun plus(x: Long) = Counter(value + x)
}
syncClient.maps.mutateItem<Counter>("mapName", "counter") { counter -> counter?.let { it + 1 } ?: Counter(1) }
Content copied to clipboard
Return
SyncMap.Item which has been set during mutation.
Parameters
map Sid Or Unique Name
SID or unique name of existing SyncMap.
item Key
Key of the item to mutate.
mutator
Mutator which will be applied to the map item.
This function will be provided with the
previous data contents and should return new desired contents or null to abort
mutate operation. This function is invoked on a background thread.
Content copied to clipboard
Throws
Twilio Exception
When error occurred while mutating the Item.