From 22b77abb905cd12af7e1b3d5f1d6f8f927da18df Mon Sep 17 00:00:00 2001 From: juhlig Date: Mon, 23 Apr 2018 17:23:33 +0200 Subject: Add gen_statem template [skip ci] --- plugins/bootstrap.mk | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'plugins') diff --git a/plugins/bootstrap.mk b/plugins/bootstrap.mk index 8e8b1b1..8ba8b08 100644 --- a/plugins/bootstrap.mk +++ b/plugins/bootstrap.mk @@ -252,6 +252,51 @@ code_change(_OldVsn, StateName, StateData, _Extra) -> {ok, StateName, StateData}. endef +define tpl_gen_statem +-module($(n)). +-behaviour(gen_statem). + +%% API. +-export([start_link/0]). + +%% gen_statem. +-export([callback_mode/0]). +-export([init/1]). +-export([state_name/3]). +-export([handle_event/4]). +-export([terminate/3]). +-export([code_change/4]). + +-record(state, { +}). + +%% API. + +-spec start_link() -> {ok, pid()}. +start_link() -> + gen_statem:start_link(?MODULE, [], []). + +%% gen_statem. + +callback_mode() -> + state_functions. + +init([]) -> + {ok, state_name, #state{}}. + +state_name(_EventType, _EventData, StateData) -> + {next_state, state_name, StateData}. + +handle_event(_EventType, _EventData, StateName, StateData) -> + {next_state, StateName, StateData}. + +terminate(_Reason, _StateName, _StateData) -> + ok. + +code_change(_OldVsn, StateName, StateData, _Extra) -> + {ok, StateName, StateData}. +endef + define tpl_cowboy_loop -module($(n)). -behaviour(cowboy_loop_handler). -- cgit v1.2.3