ETS table select_take

This is a cross post from the Erlang Forums. ETS table `select_take` - Proposals: Ideas - Erlang Programming Language Forum - Erlang Forums


I’ve been in need for an ets:select_take function. Currently a select of all keys for matching elements followed by a take is required since select_delete returns only the number of deleted elements. Could also do a select/match followed by a delete but that would mean some updates would technically succeed on an element but not be part of what was selected.

Curious if anyone else has encountered need for this and if anyone knows what an implementation would look like.

4 Likes

I’ve noticed this hole in the :ets API as well, though I can’t say I have any idea how to implement. I think it’s a great proposal!

2 Likes

You mean a concurrent update? Can you elaborate on this?

I assume it is a pop of the matched records.

take

Returns and removes a list of all objects with key Key in table Table.

Yea. An update that happens in another process during the selecting/deleting. So you select the elements, get some element A and in another process A is updated, which succeeds but then A is deleted from the table. Better, in some cases, that the update to A fails instead of being silently lost.

2 Likes