Skip to content

Create an Update method for atomic Get+Set #133

@tbrisker

Description

@tbrisker

If the map values are structs, sometimes there is a need to update a certain value inside one of the structs atomically, to ensure the updated value is consistent.
Currently the only way of doing so (other than implement an additional locking mechanism or ) is using Upsert, with a very clunky usage, for example:

var clusters = cmap.New[ClusterData]()
...   
clusters.Upsert(id, ClusterData{}, func(_ bool, cluster ClusterData, _ ClusterData) ClusterData {
	cluster.TimedOut = true
	return cluster
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions