The scope of process name?

Almost correct @elixirnewbie! That process will only be accessible locally via the name :process_name, but not from other nodes connected to the one starting the agent.

To make the agent available to all connected nodes (and nodes that will connect in the future), you have to use the tuple {:global, :process_name}, both when starting the process and fetching it through the Agent functions. Like so:

# In node 1
{:ok, pid} = Agent.start_link(fn -> 10 end, name: {:global, :process_name})
# {:ok, #PID<0.105.0>}

# In node 2
Agent.get({:global, :process_name}, fn i -> i end)
# 10

# same applies to node 1 itself
Agent.get({:global, :process_name}, fn i -> i end)
# 10
3 Likes