Skip to content

Registered subjects #45

Closed
Closed
@dvic

Description

@dvic

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:

https://github.com/erlang/otp/blob/79bc8234396a4f619f40dadfb8458064ab29aa85/lib/stdlib/src/gen.erl#L622-L640

Are there any problems with this solution?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions