riot icon indicating copy to clipboard operation
riot copied to clipboard

Process dictionary

Open alexeyshch opened this issue 1 year ago • 2 comments

Having something like Erlang's process dictionary would be useful. Maybe with API like Eio.Fiber.with_binding or Lwt.with_value.

alexeyshch avatar Jan 08 '24 06:01 alexeyshch

Hi @alexeyshch! thanks for opening the issue ✨ do you have a use-case for this that can't be solved with some local mutable state in a process?

leostera avatar Jan 08 '24 09:01 leostera

I guess it can always be solved by passing a state around, but it might not be convenient. Here are use-cases where I think using dictionary is reasonable:

  • In Erlang's mnesia application, mnesia:transaction/1 is using process dictionary to pass some data to calls like mnesia:read or mnesia:write.
  • Similarly in ejabberd, ejabberd_sql:sql_transaction is using it to pass state data to SQL queries inside it. When porting it to Lwt and Eio I used with_* calls mentioned above to keep the same API.
  • Also in ejabberd some usage statistics is put into the process dictionary, because it's much cheaper to read it with erlang:process_info than to do gen_server:call to thousands of processes.

alexeyshch avatar Jan 08 '24 21:01 alexeyshch