Though our counter is an oversimplification, the basic approach has been used for over thirty years to manage both concurrent state and behavior for most important Erlang applications. The library encapsulating that approach is called OTP, and the abstraction is called a generic server, or GenServer. Let’s modify our counter to use OTP to create our counter, instead.
We don’t need to change too much. Instead of creating specific functions to handle inc, dec, and val, we use specific OTP abstractions instead. Update your counter.ex file with these contents:
|1:||defmodule Rumbl.Counter do|
|-||def inc(pid), do: GenServer.cast(pid, :inc)|