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

sync: Map.Delete to return deleted value #25396

Closed
localvar opened this issue May 15, 2018 · 7 comments
Closed

sync: Map.Delete to return deleted value #25396

localvar opened this issue May 15, 2018 · 7 comments
Labels
FeatureRequest FrozenDueToAge v2 A language change or incompatible library change

Comments

@localvar
Copy link

I need to know if an item is actually deleted when call Delete of sync.Map, but the function returns nothing currently.

Is it possible for it to return the deleted value and/or a bool to indicate whether something is really deleted?

Thanks.

@agnivade
Copy link
Contributor

It is not possible to do that without breaking Go1 compatibility. I assume that you don't want to make an extra .Load call to check whether the element is present in the map or not ?

@agnivade agnivade added v2 A language change or incompatible library change FeatureRequest labels May 15, 2018
@agnivade
Copy link
Contributor

/cc @bcmills

@localvar
Copy link
Author

@agnivade, thanks for the reply. However, I don't think an extra .Load call works, because the item could be deleted in another go-routine between my call to .Load and .Delete.

I have little knowledge about Go1 compatibility, but in my understanding, add return value to .Delete won't break any existing code, because it currently returns nothing.

@davecheney
Copy link
Contributor

davecheney commented May 15, 2018

@localvar 'fraid not, the current interpretation of the Go 1 contract assumes that someone has assigned a method as a function; eg

var m sync.Map
var del = m.Delete

Changing the signature of sync.Map.Delete could break code like this, depending on how del is used, hence this type of proposal is not acceptable under the Go1 contract.

@davecheney
Copy link
Contributor

Duplicate of #23547 and closing as #23547 states that this change cannot be accepted.

@agnivade
Copy link
Contributor

Ah I was pretty sure this was raised before but could not find anything when I searched. Thanks.

@localvar
Copy link
Author

Is adding a new function (for an ugly example: Delete2) acceptable?

I checked the source code and find the internal entry.delete does have a return value.

@golang golang locked and limited conversation to collaborators May 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest FrozenDueToAge v2 A language change or incompatible library change
Projects
None yet
Development

No branches or pull requests

4 participants