Last active
November 13, 2019 15:30
-
-
Save eproxus/28fd864e2ba607d13ed4f5abc89ca27a to your computer and use it in GitHub Desktop.
Erlang Behaviour Templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(). | |
-behavior(gen_event). | |
% Callbacks | |
-export([init/1]). | |
-export([handle_event/2]). | |
-export([handle_call/2]). | |
-export([handle_info/2]). | |
-export([terminate/2]). | |
%--- Callbacks ----------------------------------------------------------------- | |
init(_Args) -> {ok, undefined}. | |
handle_event(Event, _State) -> error({unknown_event, Event}). | |
handle_call(Request, _State) -> error({unknown_request, Request}). | |
handle_info(Info, _State) -> error({unknown_info, Info}). | |
terminate(_Arg, _State) -> undefined. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(). | |
-behavior(gen_server). | |
% API | |
-export([start_link/0]). | |
% Callbacks | |
-export([init/1]). | |
-export([handle_call/3]). | |
-export([handle_cast/2]). | |
-export([handle_info/2]). | |
%--- API ----------------------------------------------------------------------- | |
start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, undefined, []). | |
%--- Callbacks ----------------------------------------------------------------- | |
init(undefined) -> {ok, undefined}. | |
handle_call(Request, From, _State) -> error({unknown_request, Request, From}). | |
handle_cast(Request, _State) -> error({unknown_cast, Request}). | |
handle_info(Info, _State) -> error({unknown_info, Info}). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(). | |
-behavior(gen_statem). | |
% API | |
-export([start_link/0]). | |
% Callbacks | |
-export([init/1]). | |
-export([callback_mode/0]). | |
-export([handle_event/4]). | |
%--- API ----------------------------------------------------------------------- | |
start_link() -> gen_statem:start_link({local, ?MODULE}, ?MODULE, undefined, []). | |
%--- Callbacks ----------------------------------------------------------------- | |
init(undefined) -> {ok, state, data}. | |
callback_mode() -> handle_event_function. | |
handle_event({call, _From}, EventData, State, _Data) -> | |
error({unhandled_call, EventData, State}); | |
handle_event(Event, EventData, State, _Data) -> | |
error({unhandled_event, Event, EventData, State}). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(). | |
-behaviour(supervisor). | |
% API | |
-export([start_link/0]). | |
% Callbacks | |
-export([init/1]). | |
%--- API ----------------------------------------------------------------------- | |
start_link() -> | |
supervisor:start_link({local, ?MODULE}, ?MODULE, []). | |
%--- Callbacks ----------------------------------------------------------------- | |
init([]) -> | |
{ok, {#{}, []}}. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment