Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an Update method for atomic Get+Set #133

Open
tbrisker opened this issue Apr 2, 2023 · 0 comments · May be fixed by #134
Open

Create an Update method for atomic Get+Set #133

tbrisker opened this issue Apr 2, 2023 · 0 comments · May be fixed by #134

Comments

@tbrisker
Copy link

tbrisker commented Apr 2, 2023

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
})
@tbrisker tbrisker linked a pull request Apr 2, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant