Naming Processes Using the Registry

Until now, we used the process identifier we obtained from starting the process to interact with it. However, we can optionally provide a :name value when starting a process, which can be used later on instead of a PID. This way you don’t have to keep track of the PIDs of the processes you’re starting. Functions like GenServer.cast/2 and GenServer.call/3 also accept a name instead of a process identifier, and you’ve already seen how to use Process.whereis/1 to find out the PID for JobRunner.

To make working with names easier, Elixir comes with a module called Registry. It is a very efficient key-value store with some useful functionality. Let’s see how we can use it.

Processes can be named when they start ...

Get Concurrent Data Processing in Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.