rewrite from lager
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.1 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. -module(crash_statem).
  2. %% we're only going to compile this on OTP 19+
  3. -behaviour(gen_statem).
  4. -export([
  5. start/0,
  6. crash/0,
  7. stop/1,
  8. timeout/0,
  9. handle_event/4
  10. ]).
  11. -export([terminate/3, code_change/4, init/1, callback_mode/0]).
  12. start() ->
  13. gen_statem:start({local, ?MODULE}, ?MODULE, [], []).
  14. crash() ->
  15. gen_statem:call(?MODULE, boom).
  16. stop(Reason) ->
  17. gen_statem:call(?MODULE, {stop, Reason}).
  18. timeout() ->
  19. gen_statem:call(?MODULE, timeout).
  20. %% Mandatory callback functions
  21. terminate(_Reason, _State, _Data) -> ok.
  22. code_change(_Vsn, State, Data, _Extra) -> {ok, State, Data}.
  23. init([]) ->
  24. %% insert rant here about breaking changes in minor versions...
  25. case erlang:system_info(version) of
  26. "8.0" -> {callback_mode(), state1, undefined};
  27. _ -> {ok, state1, undefined}
  28. end.
  29. callback_mode() -> handle_event_function.
  30. %%% state callback(s)
  31. handle_event(state_timeout, timeout, state1, _) ->
  32. {stop, timeout};
  33. handle_event({call, _From}, timeout, _Arg, _Data) ->
  34. {keep_state_and_data, [{state_timeout, 0, timeout}]};
  35. handle_event({call, _From}, {stop, Reason}, state1, _Data) ->
  36. {stop, Reason}.