January 2013
Beginner to intermediate
204 pages
4h 26m
English
These are the full templates for gen_server, supervisor, and application from the Emacs mode for Erlang. Some pieces are more useful than others, but seeing the full set of expected responses can be useful. (In this context, a template is just a file full of code you can use as a base for creating your own code.)
Remember, the noreply atom doesn’t mean “there will never be a reply” but rather that “this response isn’t a reply.”
%%%-------------------------------------------------------------------%%% @author $author%%% @copyright (C) $year, $company%%% @doc%%%%%% @end%%% Created : $fulldate%%%--------------------------------------------------------------------module($basename).-behaviour(gen_server).%% API-export([start_link/0]).%% gen_server callbacks-export([init/1,handle_call/3,handle_cast/2,handle_info/2,terminate/2,code_change/3]).-define(SERVER,?MODULE).-record(state,{}).%%%===================================================================%%% API%%%===================================================================%%--------------------------------------------------------------------%% @doc%% Starts the server%%%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}%% @end%%--------------------------------------------------------------------start_link()->gen_server:start_link({local,?SERVER},?MODULE,[],[]).%%%=================================================================== ...