Need help registring names for GenServer

I need help with gen server. I have an application that runs a supervisor which ensures a Coordinator is running. this coordinator is a genserver mostly due to the nature of the calls. said coordinator is responsible for spawning a set of simple workers which will then report the results of their work back to the inital server. My issue is this

I saw mention that you can get Genserver to register a process globally on its start_link function which you can then use when casting to the server in question. but i am not getting this to work. though i pass [global: :coordinator] into the options section of the start link function it does not register the name, please help
that is the internal start_link in question which actually starts this application in said genserver’s module
-> GenServer.start_link(CCoordinator, [], global: CCoordinator)

Hello and welcome to the forum,

Usually :global is for distributed network, it is used with :global module.

If You are not in a distributed network, You can use

GenServer.start_link(__MODULE__, args, name: __MODULE__)

or if the worker is dynamic…

GenServer.start_link(__MODULE__, args, name: via_tuple(name))
...
defp via_tuple(name), do: {:via, Registry, {Registry.WorldWorkers, name}}

# and in application.ex, add Registry to supervision tree

{Registry, keys: :unique, name: Registry.WorldWorkers},
2 Likes

Thanks, Worked like a charm