@@ -1490,9 +1537,9 @@ handle_event(_, _, State, Data) ->
The CallbackMode is either just
- callback_mode()
+ callback_mode()
or a list containing
- callback_mode()
+ callback_mode()
and possibly the atom
state_enter.
diff --git a/lib/stdlib/src/gen_statem.erl b/lib/stdlib/src/gen_statem.erl
index aedcfc932f..9f5573af86 100644
--- a/lib/stdlib/src/gen_statem.erl
+++ b/lib/stdlib/src/gen_statem.erl
@@ -142,7 +142,7 @@
NextStateName :: state_name(),
NewData :: data(),
Actions :: [action()] | action()} |
- common_state_callback_result().
+ keep_state_callback_result().
-type state_function_enter_result() ::
{'next_state', % {next_state,NextStateName,NewData,[]}
NextStateName :: state_name(),
@@ -151,7 +151,7 @@
NextStateName :: state_name(),
NewData :: data(),
Actions :: [enter_action()] | enter_action()} |
- common_state_callback_result().
+ keep_state_callback_enter_result().
-type handle_event_result() ::
{'next_state', % {next_state,NextState,NewData,[]}
@@ -161,7 +161,7 @@
NextState :: state(),
NewData :: data(),
Actions :: [action()] | action()} |
- common_state_callback_result().
+ keep_state_callback_result().
-type handle_event_enter_result() ::
{'next_state', % {next_state,NextState,NewData,[]}
NextState :: state(),
@@ -170,6 +170,28 @@
NextState :: state(),
NewData :: data(),
Actions :: [enter_action()] | enter_action()} |
+ keep_state_callback_enter_result().
+
+-type keep_state_callback_result() ::
+ {'keep_state', % {keep_state,NewData,[]}
+ NewData :: data()} |
+ {'keep_state', % Keep state, change data
+ NewData :: data(),
+ Actions :: [action()] | action()} |
+ 'keep_state_and_data' | % {keep_state_and_data,[]}
+ {'keep_state_and_data', % Keep state and data -> only actions
+ Actions :: [action()] | action()} |
+ common_state_callback_result().
+
+-type keep_state_callback_enter_result() ::
+ {'keep_state', % {keep_state,NewData,[]}
+ NewData :: data()} |
+ {'keep_state', % Keep state, change data
+ NewData :: data(),
+ Actions :: [enter_action()] | enter_action()} |
+ 'keep_state_and_data' | % {keep_state_and_data,[]}
+ {'keep_state_and_data', % Keep state and data -> only actions
+ Actions :: [enter_action()] | enter_action()} |
common_state_callback_result().
-type common_state_callback_result() ::
@@ -185,15 +207,7 @@
{'stop_and_reply', % Reply then stop the server
Reason :: term(),
Replies :: [reply_action()] | reply_action(),
- NewData :: data()} |
- {'keep_state', % {keep_state,NewData,[]}
- NewData :: data()} |
- {'keep_state', % Keep state, change data
- NewData :: data(),
- Actions :: [ActionType] | ActionType} |
- 'keep_state_and_data' | % {keep_state_and_data,[]}
- {'keep_state_and_data', % Keep state and data -> only actions
- Actions :: [ActionType] | ActionType}.
+ NewData :: data()}.
%% The state machine init function. It is called only once and
diff --git a/system/doc/design_principles/statem.xml b/system/doc/design_principles/statem.xml
index d2a9b23570..69d1e8e9fa 100644
--- a/system/doc/design_principles/statem.xml
+++ b/system/doc/design_principles/statem.xml
@@ -29,7 +29,7 @@
statem.xml
-
+
This section is to be read with the
gen_statem(3)
@@ -199,7 +199,10 @@ handle_event(EventType, EventContent, State, Data) ->
State Enter Calls
The gen_statem behavior can regardless of callback mode
- automatically call the state function
+ automatically
+
+ call the state function
+
with special arguments whenever the state changes
so you can write state entry actions
near the rest of the state transition rules.
@@ -214,8 +217,13 @@ StateName(EventType, EventContent, Data) ->
{next_state, NewStateName, NewData}.
Depending on how your state machine is specified,
- this can be a very useful feature, but if you use it
- you will have to handle the state enter call in all states.
+ this can be a very useful feature,
+ but it forces you to handle the state enter calls in all states.
+ See also the
+
+ State Entry Actions
+
+ chapter.
@@ -964,6 +972,7 @@ do_unlock() ->
+
State Entry Actions
Say you have a state machine specification
--
cgit v1.2.3