genserver
Much of the work you think of as the core of a program - calculating results, storing information, and preparing replies - will fit neatly into the
gen_server
behavior. It provides a core set of methods that let you set up a process, respond to requests, end the process gracefully, and even pass state to a new process if this one needs to be upgraded in place. (Laurent 2017, 148)
gen_server
is a generic server process that implements a standard set of
interface functions and functionality for tracing and error reporting, it also
fits an OTP supervision tree.
The gen_server
behaviour interface contains six functions:
init/1
handle_call/3
: Sends a synchronous message to agen_server
process and waits for a reply.handle_cast/2
: Sends an asynchronous message to agen_server
process.handle_info/2
: Handles messages sent to agen_server
container that were not sent using one of the call or cast functions.terminate/2
: When agen_server
shuts down, this callback is raised to give you a chance to clean things up.code_change/3