diff options
author | Raimo Niskanen <raimo@erlang.org> | 2020-01-31 15:55:03 +0100 |
---|---|---|
committer | Raimo Niskanen <raimo@erlang.org> | 2020-02-11 17:14:58 +0100 |
commit | 095cd40ddfdceaed7b6fdf484658051c40271a9d (patch) | |
tree | 247bffaa2a3c664fd95124b115179a88a6ebfd46 /lib/stdlib/src | |
parent | d43db6a8644903ee82b8d69872d55ad361522ad0 (diff) | |
download | erlang-095cd40ddfdceaed7b6fdf484658051c40271a9d.tar.gz |
Implement change_callback_module
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r-- | lib/stdlib/src/gen_statem.erl | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/lib/stdlib/src/gen_statem.erl b/lib/stdlib/src/gen_statem.erl index 5d750884cf..885c6ef031 100644 --- a/lib/stdlib/src/gen_statem.erl +++ b/lib/stdlib/src/gen_statem.erl @@ -149,6 +149,7 @@ {'next_event', % Insert event as the next to handle EventType :: event_type(), EventContent :: term()} | + {'change_callback_module', NewModule :: module()} | enter_action(). -type enter_action() :: 'hibernate' | % Set the hibernate option @@ -337,12 +338,13 @@ terminate/3, % Has got a default implementation code_change/4, % Only needed by advanced soft upgrade %% - state_name/3, % Example for callback_mode() =:= state_functions: + state_name/3, % Just an example callback; + %% for callback_mode() =:= state_functions %% there has to be a StateName/3 callback function - %% for every StateName in your state machine but the state name - %% 'state_name' does of course not have to be used. + %% for every StateName in your state machine, + %% but not one has to be named 'state_name' %% - handle_event/4 % For callback_mode() =:= handle_event_function + handle_event/4 % Only for callback_mode() =:= handle_event_function ]). @@ -1443,6 +1445,28 @@ loop_actions_list( P, Debug, S, Q, NextState_NewData, NextEventsR, Hibernate, TimeoutsR, Postpone, CallEnter, StateCall, Actions, Type, Content); + %% + {change_callback_module, NewModule} + when is_atom(NewModule) -> + if + StateCall -> + P_1 = + P#params{ + callback_mode = undefined, module = NewModule}, + loop_actions_list( + P_1, Debug, S, Q, NextState_NewData, + NextEventsR, Hibernate, TimeoutsR, Postpone, + CallEnter, StateCall, Actions); + true -> + terminate( + error, + {bad_state_enter_action_from_state_function,Action}, + ?STACKTRACE(), P, Debug, + S#state{ + state_data = NextState_NewData, + hibernate = Hibernate}, + Q) + end; %% Timeout -> loop_actions_timeout( |