May 2018
Intermediate to advanced
412 pages
9h 3m
English
GenServer is an OTP protocol. OTP works by assuming that your module defines a number of callback functions (six, in the case of a GenServer). If you were writing a GenServer in Erlang, your code would have to contain implementations of all six.
When you add the line ‘use GenServer‘ to a module, Elixir creates default implementations of these six callback functions. All we have to do is override the ones where we add our own application-specific behavior. Our examples so far have used the three callbacks ‘init‘, ‘handle_call‘, and ‘handle_cast‘. Here’s a full list:
Called by GenServer when starting a new server. The parameter is the second argument passed to start_link. It should return {:ok, state} ...
Read now
Unlock full access