concept consumer process in category elixir

This is an excerpt from Manning's book The Little Elixir & OTP Guidebook.
When a consumer process checks out a worker from the pool, you need to handle a few key logistical issues:
What is the pid of the consumer process? Which worker pid is the consumer process using? The consumer process needs to be monitored by the server because if it dies, the server process must know about it and take recovery action. Once again, you aren’t implementing the recovery code yet, but laying the groundwork.
For the last bit of Pooly, you’re going to handle the case where consumers are willing to wait for a worker to be available. In other words, the consumer process is willing to block until the worker pool frees up a worker. For this to work, you need to queue up worker processes and match a newly freed worker process with a waiting consumer process.
A crash of the server process shouldn’t affect a consumer process—and the reverse is also true! When a consumer process crashes, it shouldn’t crash the server process. Therefore, monitors are the way to go.
You’re already monitoring the consumer process each time a worker is checked out. What’s left is to handle the :DOWN message of a consumer process, as the next listing shows.
Listing 7.1. Handling the consumer :DOWN message (lib/pooly/server.ex)
defmodule Pooly.Server do ############# # Callbacks # ############# def handle_info({:DOWN, ref, _, _, _}, state = %{monitors: monitors, workers: workers}) do case :ets.match(monitors, {:"$1", ref}) do [[pid]] -> true = :ets.delete(monitors, pid) new_state = %{state | workers: [pid|workers]} #1 {:noreply, new_state} [[]] -> {:noreply, state} end end endWhen a consumer process goes down, you match the reference in the monitors ETS table, delete the monitor, and add the worker back into the state.