Build a Server with a Process

In this chapter, we’re going to build a calculator service. First, we’re going to build the core of our service, the piece that does the actual computation. Then we’re going to wrap our core layer in a boundary layer that will hold the calculator value as we add calculations, one at a time. Though we haven’t formally mixed in OTP yet, this boundary layer is the realm of the OTP GenServer. It will have a message loop, a means to start, and a means to send messages.

The main building block of OTP is the GenServer. These tiny services are not necessarily network servers. Instead, they are functions running in a process in a recursive message loop. Rather than explain things with words, let’s show some rough code that ...

Get Programmer Passport: OTP 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.