October 2014
Intermediate to advanced
280 pages
7h 20m
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 behaviour. Our examples so far have used the two callbacks 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. Should return {:ok, state} on success, or {:stop, ...
Read now
Unlock full access