Description
The README of gleam/otp mentions
There is no support for named processes. They are untyped global mutable variables which may be uninitialized, more research is needed to find a suitable type safe alternative.
I just wanted to drop a thought here and see if we can further explore a solution to this.
We now have the Subject
, which is an opaque type:
pub opaque type Subject(message) {
Subject(owner: Pid, tag: Reference)
}
As far as I understood is that the current approach to using supervised actors is to send the subject to the parent proces. I propose that we keep it like that, but instead of new_subject
in the actor we do something like new_local_subject(name)
and have
pub opaque type Subject(message) {
// no name registration
Subject(owner: Pid, tag: Reference)
// for node-local name registration
LocalSubject(name: Atom, tag: Reference)
// for cluster-wide global name registration
GlobalSubject(name: Atom, tag: Reference)
}
So basically everything remains the same but we don't need to handle actor restarts in our code explicitly: when the actor restarts it will register again under the same name.
Local, global and possible in the future custom registration can be done like in erlang:
Are there any problems with this solution?