[erlang-questions] atomic ETS update with a function?

Sverker Eriksson sverker@REDACTED
Tue Nov 20 15:05:24 CET 2018


You can use ets:select_replace/2 to do an atomic compare-and-swap operation:
[Old] = ets:lookup(T, Key),
New = update_object(Old),
Success = (1 =:= ets:select_replace(T, [{Old, [], [{const, New}]}])),
ets:select_replace/2 was introduced in OTP-20.
/Sverker
	
On mån, 2018-11-19 at 18:44 +0000, Vans S wrote:
> Currently there is no atomic function to update a ETS value when its not a
> tuple.  For example if one of my ETS values is a map, and I want to put an
> element into the map, I have no atomic way to do so.
> 
> Is there anyone else that really has a need for a function like :ets.update/3
> where arg 1 is ets_table, 2 is key, 3 is fun callback that is called passing
> the original element and the reply should be the new element?
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20181120/6dc12242/attachment.htm>


More information about the erlang-questions mailing list