October 2019
Intermediate to advanced
358 pages
8h 22m
English
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 InfoSys.Counter do |
| - | use GenServer |
| - | |
| - | def inc(pid), do: GenServer.cast(pid, ... |
Read now
Unlock full access