In ets, concurrently write a key whose value is a list or map. In order to ensure data consistency, the current scheme is to cast/call the write operation request to the special write process for processing. In most cases, the code is not natural to write in this way, and the write process may have performance bottlenecks.
I would like to ask why ets:update_with_fun(Table, Key, Fun) doesn’t exist in ets api. It seems that implementing such a function is not easy.
Then I saw that there was now a function that did just that :ets:select_replace(Table, MatchSpec), But MatchSpec does not support lists:delete() maps:remove() setelement() calls.
Or is there a better way to do it in erlang scenarios?
I guess the main reason is that ets is implemented as a NIF/BIF (native C functions). And currently BEAM does not allow to execute erlang code (call erlang functions, execute funs) from BIF/NIF.
I think the only way currently is, as you said, to use a separate writer process. I think Mnesia does exactly this to implement transactions on top of ETS/DETS (this process is called mnesia_locker if I remember correctly)