Is the process dictionary appropriate in this case?

The general rule is that if you have doubts, you shouldn't use the process dictionary.

If the two options you mentioned aren't good enough (I personally like the one where you return the messages to send) and what you want is some particular piece of code to track users and forward messages to them, maybe what you want to do is have a process holding that info.

Pid ! {forward, Msg}

where Pid will take care of sending everything to a bunch of other processes. Now, you would still need to pass the Pid around, unless you give it a name in some registry to find it. Either with register/2, global or gproc.


A simple answer would be to nest your global within a state record, which is then threaded through the system, at least at the stop level. This makes it easy to add new fields to the state in the future, not an uncommon occurrence, and allow you to keep your global state data structure untouched. So initially

-record(state, {users=[],state_data}).

Defining it as a record makes it easy to access and extend when necessary.

Tags:

Erlang