rewrite from lager
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 

46 righe
1.1 KiB

-module(crash_statem).
%% we're only going to compile this on OTP 19+
-behaviour(gen_statem).
-export([
start/0,
crash/0,
stop/1,
timeout/0,
handle_event/4
]).
-export([terminate/3, code_change/4, init/1, callback_mode/0]).
start() ->
gen_statem:start({local, ?MODULE}, ?MODULE, [], []).
crash() ->
gen_statem:call(?MODULE, boom).
stop(Reason) ->
gen_statem:call(?MODULE, {stop, Reason}).
timeout() ->
gen_statem:call(?MODULE, timeout).
%% Mandatory callback functions
terminate(_Reason, _State, _Data) -> ok.
code_change(_Vsn, State, Data, _Extra) -> {ok, State, Data}.
init([]) ->
%% insert rant here about breaking changes in minor versions...
case erlang:system_info(version) of
"8.0" -> {callback_mode(), state1, undefined};
_ -> {ok, state1, undefined}
end.
callback_mode() -> handle_event_function.
%%% state callback(s)
handle_event(state_timeout, timeout, state1, _) ->
{stop, timeout};
handle_event({call, _From}, timeout, _Arg, _Data) ->
{keep_state_and_data, [{state_timeout, 0, timeout}]};
handle_event({call, _From}, {stop, Reason}, state1, _Data) ->
{stop, Reason}.