Naming GenServer Processes

This whole chapter we’ve been starting new GenServer processes and binding their PIDs to variables. Whenever we’ve needed to call a public function on a process, we’ve passed that variable in as the first argument. That clearly works, but it leaves us with a problem.

In a full application, we’d need to keep track of every variable for every process we started. We’d need to always keep them in scope, and we’d need to clear individual variables out when their process stopped. If that sounds really messy, it is.

It would be great if we could just name each process as we start it, and pass that name in whenever we wanted to call a function. It would be even better if we didn’t have to remember the name, but were able to ...

Get Functional Web Development with Elixir, OTP, and Phoenix 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.