riot
riot copied to clipboard
Process dictionary
Having something like Erlang's process dictionary would be useful. Maybe with API like Eio.Fiber.with_binding or Lwt.with_value.
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?
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 likemnesia:read
ormnesia: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 usedwith_*
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 dogen_server:call
to thousands of processes.