Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process dictionary #38

Open
alexeyshch opened this issue Jan 8, 2024 · 2 comments
Open

Process dictionary #38

alexeyshch opened this issue Jan 8, 2024 · 2 comments

Comments

@alexeyshch
Copy link

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

@leostera
Copy link
Collaborator

leostera commented Jan 8, 2024

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?

@alexeyshch
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants