aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/stdlib/doc/src/gen_statem.xml222
-rw-r--r--lib/stdlib/src/gen_statem.erl382
-rw-r--r--lib/stdlib/test/gen_statem_SUITE.erl44
3 files changed, 338 insertions, 310 deletions
diff --git a/lib/stdlib/doc/src/gen_statem.xml b/lib/stdlib/doc/src/gen_statem.xml
index c685d24b78..15e9584360 100644
--- a/lib/stdlib/doc/src/gen_statem.xml
+++ b/lib/stdlib/doc/src/gen_statem.xml
@@ -94,7 +94,7 @@ erlang:'!' -----> Module:StateName/5
<seealso marker="#Module:StateName/5">
<c>Module:StateName/5</c>
</seealso>.
- This naturally collects all code for a specific state
+ This gathers all code for a specific state
in one function and hence dispatches on state first.
</p>
<p>When
@@ -135,8 +135,8 @@ erlang:'!' -----> Module:StateName/5
<p>The
<seealso marker="#state_function">state function</seealso>
can insert events using the
- <seealso marker="#type-state_operation">
- <c>state_operation()</c> <c>next_event</c>
+ <seealso marker="#type-transition_action">
+ <c>transition_action()</c> <c>next_event</c>
</seealso>
and such an event is inserted as the next to present
to the state function. That is: as if it is
@@ -176,8 +176,8 @@ erlang:'!' -----> Module:StateName/5
<seealso marker="#state_function">state function</seealso> or
<seealso marker="#Module:init/1"><c>Module:init/1</c></seealso>
specifies <c>'hibernate'</c> in the returned
- <seealso marker="#type-state_op"><c>StateOps</c></seealso> list.
- This might be useful if the server is expected to be idle
+ <seealso marker="#type-transition_op"><c>Ops</c></seealso>
+ list. This might be useful if the server is expected to be idle
for a long time. However use this feature with care
since hibernation implies at least two garbage collections
(when hibernating and shortly after waking up) and that is not
@@ -273,8 +273,8 @@ erlang:'!' -----> Module:StateName/5
<name name="client" />
<desc>
<p>Client address to use when replying through for example the
- <seealso marker="#type-state_op">
- state_op() {reply,Client,Reply}
+ <seealso marker="#type-transition_op">
+ transition_op() {reply,Client,Reply}
</seealso>
to a client that has called the <c>gen_statem</c> server using
<seealso marker="#call/2">call/2</seealso>.
@@ -296,19 +296,21 @@ erlang:'!' -----> Module:StateName/5
<seealso marker="#type-callback_mode">
callback_mode
</seealso> is <c>state_functions</c>, which is the default,
- the state has to be of this type i.e an <c>atom()</c>.
+ the state has to be of this type.
</p>
</desc>
</datatype>
<datatype>
- <name name="state_data" />
+ <name name="data" />
<desc>
- <p>A <c>term()</c> in which the state machine implementation
- should store any state data it needs. The difference between
- this data and the
- <seealso marker="#type-state">state()</seealso>
+ <p>A term in which the state machine implementation
+ should store any server data it needs. The difference between
+ this and the <seealso marker="#type-state">state()</seealso>
itself is that a change in this data does not cause
- postponed events to be retried.
+ postponed events to be retried. Hence if a change
+ in this data would change the set of events that
+ are handled than that data item should be made
+ a part of the state.
</p>
</desc>
</datatype>
@@ -334,8 +336,8 @@ erlang:'!' -----> Module:StateName/5
<desc>
<p>A <c>fun()</c> of arity 2 that takes an event
and returns a boolean.
- When used in <c>{remove_event,RemoveEventPredicate}</c>
- from <seealso marker="#type-state_op">state_op()</seealso>.
+ When used in <c>{remove_event,RemoveEventPredicate}</c> from
+ <seealso marker="#type-transition_op">transition_op()</seealso>.
The event for which the predicate returns <c>true</c> will
be removed.
</p>
@@ -378,17 +380,16 @@ erlang:'!' -----> Module:StateName/5
</desc>
</datatype>
<datatype>
- <name name="state_op" />
+ <name name="transition_op" />
<desc>
<p>Either a
- <seealso marker="#type-state_option">
- <c>state_option()</c>
+ <seealso marker="#type-transition_option">
+ <c>transition_option()</c>
</seealso> of which the last occurence
in the containing list takes precedence, or a
- <seealso marker="#type-state_operation">
- <c>state_operation()</c>
- </seealso> that are performed in order of
- the containing list.
+ <seealso marker="#type-transition_action">
+ <c>transition_action()</c>
+ </seealso> performed in the order of the containing list.
</p>
<p>These may be returned from the
<seealso marker="#state_function">state function</seealso>,
@@ -404,7 +405,7 @@ erlang:'!' -----> Module:StateName/5
<item>If the state changes the queue of incoming events
is reset to start with the oldest postponed.
</item>
- <item>All operations are processed in order of appearance.
+ <item>All actions are processed in order of appearance.
</item>
<item>The <c>timeout</c> option is processed if present,
so a state timer may be started or a timeout zero event
@@ -424,9 +425,9 @@ erlang:'!' -----> Module:StateName/5
</desc>
</datatype>
<datatype>
- <name name="state_option" />
+ <name name="transition_option" />
<desc>
- <p>If multiple state options of the same type are present
+ <p>If multiple state options of the same kind are present
in the containing list these are set in the list order
and the last value is kept.
</p>
@@ -448,7 +449,7 @@ erlang:'!' -----> Module:StateName/5
<seealso marker="proc_lib#hibernate/3">
<c>proc_lib:hibernate/3</c>
</seealso> before <c>receive</c> to wait for a new event.
- If there are enqueued events the <c>hibernate</c> operation
+ If there are enqueued events the <c>hibernate</c> action
is ignored as if an event just arrived and awakened
the <c>gen_statem</c>.
</item>
@@ -464,8 +465,8 @@ erlang:'!' -----> Module:StateName/5
is immediately enqueued as the newest received.
Also note that it is not possible nor needed
to cancel this timeout using the
- <seealso marker="#type-state_operation">
- <c>state_operation()</c>
+ <seealso marker="#type-transition_action">
+ <c>transition_action()</c>
</seealso> <c>cancel_timer</c>.
This timeout is cancelled automatically by any event.
</item>
@@ -473,17 +474,20 @@ erlang:'!' -----> Module:StateName/5
</desc>
</datatype>
<datatype>
- <name name="state_operation" />
+ <name name="transition_action" />
<desc>
- <p>The state operations are executed in the containing
- list order. This matters for <c>next_event</c> where
- the last one in the list will become the next event to present
- to the state functions. Regarding the other operations
- it is only for <c>remove_event</c> with
- <c><anno>EventPredicate</anno></c>
- and for <c>reply_operation()</c> that the order may matter.
+ <p>The state transition actions are executed
+ in the containing list order. This matters
+ for <c>next_event</c> where the last one in the list
+ will become the next event to present
+ to the state functions. Regarding the other actions
+ it is only for <c>remove_event</c> with
+ <c><anno>EventPredicate</anno></c>
+ and for <c>reply_action()</c> that the order may matter.
</p>
<taglist>
+ <tag><c>reply_action()</c></tag>
+ <item>Reply to a calling client.</item>
<tag><c>next_event</c></tag>
<item>Insert the given <c><anno>EventType</anno></c>
and <c><anno>EventContent</anno></c> the next to process.
@@ -518,7 +522,7 @@ erlang:'!' -----> Module:StateName/5
<c>demonitor/2</c>
</seealso> with <c><anno>MonitorRef</anno></c>.
</item>
- <tag><c>{unlink,<anno>Id</anno>}</c></tag>
+ <tag><c>unlink</c></tag>
<item>Like <c>{cancel_timer,_}</c> above but for
<seealso marker="erts:erlang#unlink/1">
<c>unlink/1</c>
@@ -528,7 +532,7 @@ erlang:'!' -----> Module:StateName/5
</desc>
</datatype>
<datatype>
- <name name="reply_operation" />
+ <name name="reply_action" />
<desc>
<p>Reply to a client that called
<seealso marker="#call/2"><c>call/2</c></seealso>.
@@ -550,26 +554,26 @@ erlang:'!' -----> Module:StateName/5
<seealso marker="#Module:terminate/3">
<c>Module:terminate/3</c>
</seealso> with <c>Reason</c> and
- <c><anno>NewStateData</anno></c>, if given.
+ <c><anno>NewData</anno></c>, if given.
</item>
<tag><c>next_state</c></tag>
<item>The <c>gen_statem</c> will do a state transition to
<c><anno>NewState</anno></c>
(which may be the same as the current state),
- set <c><anno>NewStateData</anno></c>
- and execute all <c><anno>StateOps</anno></c>
+ set <c><anno>NewData</anno></c>
+ and execute all <c><anno>Ops</anno></c>
</item>
<tag><c>keep_state</c></tag>
<item>The <c>gen_statem</c> will keep the current state, or
do a state transition to the current state if you like,
- set <c><anno>NewStateData</anno></c>
- and execute all <c><anno>StateOps</anno></c>
+ set <c><anno>NewData</anno></c>
+ and execute all <c><anno>Ops</anno></c>
</item>
<tag><c>keep_state_and_data</c></tag>
<item>The <c>gen_statem</c> will keep the current state, or
do a state transition to the current state if you like,
- keep the current state data,
- and execute all <c><anno>StateOps</anno></c>
+ keep the current server data,
+ and execute all <c><anno>Ops</anno></c>
</item>
</taglist>
</desc>
@@ -614,7 +618,7 @@ erlang:'!' -----> Module:StateName/5
</seealso>.
</p>
<p>If the option <c>{timeout,Time}</c> is present in
- <c><anno>Options</anno></c>, the <c>gen_statem</c>
+ <c><anno>Opts</anno></c>, the <c>gen_statem</c>
is allowed to spend <c>Time</c> milliseconds initializing
or it will be terminated and the start function will return
<seealso marker="#type-start_ret">
@@ -623,15 +627,14 @@ erlang:'!' -----> Module:StateName/5
</p>
<p>If the option
<seealso marker="#type-debug_opt"><c>{debug,Dbgs}</c></seealso>
- is present in <c><anno>Options</anno></c>, debugging through
+ is present in <c><anno>Opts</anno></c>, debugging through
<seealso marker="sys"><c>sys</c></seealso> is activated.
</p>
- <p>If the option <c>{spawn_opt,SOpts}</c> is present in
- <c><anno>Options</anno></c>, <c>SOpts</c> will be passed
- as option list to the <c>spawn_opt</c> BIF
- which is used to
- <seealso marker="erts:erlang#spawn_opt/2">spawn</seealso>
- the <c>gen_statem</c>.
+ <p>If the option <c>{spawn_opt,SpawnOpts}</c> is present in
+ <c><anno>Opts</anno></c>, <c>SpawnOpts</c> will be passed
+ as option list to
+ <seealso marker="erts:erlang#spawn_opt/2">spawn_opt/2</seealso>
+ which is used to spawn the <c>gen_statem</c> process.
</p>
<note>
<p>Using the spawn option <c>monitor</c> is currently not
@@ -760,7 +763,9 @@ erlang:'!' -----> Module:StateName/5
<seealso marker="#state_function">state function</seealso>
returns with
<c>{reply,Client,<anno>Reply</anno>}</c> as one
- <seealso marker="#type-state_op"><c>state_op()</c></seealso>,
+ <seealso marker="#type-transition_op">
+ <c>transition_op()</c>
+ </seealso>,
and that <c><anno>Reply</anno></c> becomes the return value
of this function.
</p>
@@ -823,8 +828,8 @@ erlang:'!' -----> Module:StateName/5
<seealso marker="#state_function">state function</seealso>.
<c><anno>Client</anno></c> and <c><anno>Reply</anno></c>
can also be specified using a
- <seealso marker="#type-reply_operation">
- <c>reply_operation()</c>
+ <seealso marker="#type-reply_action">
+ <c>reply_action()</c>
</seealso> and multiple replies with a list of them.
</p>
<note>
@@ -852,20 +857,20 @@ erlang:'!' -----> Module:StateName/5
<name name="enter_loop" arity="5" />
<fsummary>Enter the <c>gen_statem</c> receive loop</fsummary>
<desc>
- <p>If <c><anno>Server_or_StateOps</anno></c> is a <c>list()</c>
+ <p>If <c><anno>Server_or_Ops</anno></c> is a <c>list()</c>
the same as
<seealso marker="#enter_loop/6"><c>enter_loop/6</c></seealso>
except that no
<seealso marker="#type-server_name">
<c>server_name()</c>
</seealso> must have been registered and
- <c>StateOps = <anno>Server_or_StateOps</anno></c>.
+ <c>Ops = <anno>Server_or_Ops</anno></c>.
</p>
<p>Otherwise the same as
<seealso marker="#enter_loop/6"><c>enter_loop/6</c></seealso>
with
- <c>Server = <anno>Server_or_StateOps</anno></c> and
- <c>StateOps = []</c>.
+ <c>Server = <anno>Server_or_Ops</anno></c> and
+ <c>Ops = []</c>.
</p>
</desc>
</func>
@@ -887,7 +892,7 @@ erlang:'!' -----> Module:StateName/5
procedure is needed than
the <c>gen_statem</c> behaviour provides.
</p>
- <p><c><anno>Module</anno></c>, <c><anno>Options</anno></c> and
+ <p><c><anno>Module</anno></c>, <c><anno>Opts</anno></c> and
<c><anno>Server</anno></c> have the same meanings
as when calling
<seealso marker="#start_link/3">
@@ -898,8 +903,8 @@ erlang:'!' -----> Module:StateName/5
<c>server_name()</c>
</seealso> name must have been registered accordingly
<em>before</em> this function is called.</p>
- <p><c><anno>State</anno></c>, <c><anno>StateData</anno></c>
- and <c><anno>StateOps</anno></c>
+ <p><c><anno>State</anno></c>, <c><anno>Data</anno></c>
+ and <c><anno>Ops</anno></c>
have the same meanings as in the return value of
<seealso marker="#Module:init/1">Module:init/1</seealso>.
Also, the callback module <c><anno>Module</anno></c>
@@ -933,15 +938,14 @@ erlang:'!' -----> Module:StateName/5
<fsummary>Initialize process and internal state</fsummary>
<type>
<v>Args = term()</v>
- <v>Result = {ok,State,StateData}</v>
- <v>&nbsp;| {ok,State,StateData,StateOps}</v>
+ <v>Result = {ok,State,Data}</v>
+ <v>&nbsp;| {ok,State,Data,Ops}</v>
<v>&nbsp;| {stop,Reason} | ignore</v>
<v>State = <seealso marker="#type-state">state()</seealso></v>
- <v>StateData =
- <seealso marker="#type-state_data">state_data()</seealso>
+ <v>Data = <seealso marker="#type-data">data()</seealso>
</v>
- <v>StateOps =
- [<seealso marker="#type-state_op">state_op()</seealso>
+ <v>Ops =
+ [<seealso marker="#type-transition_op">transition_op()</seealso>
| <seealso marker="#type-init_option">init_option()</seealso>]
</v>
<v>Reason = term()</v>
@@ -953,17 +957,17 @@ erlang:'!' -----> Module:StateName/5
or
<seealso marker="#start/3">start/3,4</seealso>,
this function is called by the new process to initialize
- the implementation loop data.
+ the implementation state and server data.
</p>
<p><c>Args</c> is the <c>Args</c> argument provided to the start
function.</p>
<p>If the initialization is successful, the function should
- return <c>{ok,State,StateData}</c> or
- <c>{ok,State,StateData,StateOps}</c>.
+ return <c>{ok,State,Data}</c> or
+ <c>{ok,State,Data,Ops}</c>.
<c>State</c> is the <seealso marker="#type-state">state</seealso>
of the <c>gen_statem</c>.
</p>
- <p>The <seealso marker="#type-state_op"><c>StateOps</c></seealso>
+ <p>The <seealso marker="#type-transition_op"><c>Ops</c></seealso>
are executed when entering the first
<seealso marker="#type-state">state</seealso> just as for a
<seealso marker="#state_function">state function</seealso>.
@@ -978,15 +982,19 @@ erlang:'!' -----> Module:StateName/5
or <c>ignore</c>. See
<seealso marker="#start_link/3">start_link/3,4</seealso>.
</p>
+ <p>This function may use
+ <seealso marker="erts:erlang#throw/1"><c>throw</c></seealso>,
+ to return its value.
+ </p>
</desc>
</func>
<func>
<name>Module:StateName(EventType, EventContent,
- PrevStateName, StateName, StateData) -> Result
+ PrevStateName, StateName, Data) -> Result
</name>
<name>Module:handle_event(EventType, EventContent,
- PrevState, State, StateData) -> Result
+ PrevState, State, Data) -> Result
</name>
<fsummary>Handle an event</fsummary>
<type>
@@ -1003,8 +1011,8 @@ erlang:'!' -----> Module:StateName/5
<v>PrevState = State =
<seealso marker="#type-state">state()</seealso>
</v>
- <v>StateData = NewStateData =
- <seealso marker="#type-state_data">state_data()</seealso>
+ <v>Data = NewData =
+ <seealso marker="#type-data">data()</seealso>
</v>
<v>Result =
<seealso marker="#type-state_callback_result">
@@ -1029,8 +1037,8 @@ erlang:'!' -----> Module:StateName/5
from this or from any other
<seealso marker="#state_function">state function</seealso>
by returning with <c>{reply,Client,Reply}</c> in
- <seealso marker="#type-state_op">StateOps</seealso>, in
- <seealso marker="#type-reply_operation">Replies</seealso>
+ <seealso marker="#type-transition_op">Ops</seealso>, in
+ <seealso marker="#type-reply_action">Replies</seealso>
or by calling
<seealso marker="#reply/2">
<c>reply(Client, Reply)</c>
@@ -1050,23 +1058,25 @@ erlang:'!' -----> Module:StateName/5
does not match equal (<c>=/=</c>) to the current state
all postponed events will be retried in the new state.
</p>
- <p>See <seealso marker="#type-state_op">state_op()</seealso>
- for options that can be set and operations that can be done
+ <p>See
+ <seealso marker="#type-transition_op">transition_op()</seealso>
+ for options that can be set and actions that can be done
by <c>gen_statem</c> after returning from this function.
</p>
+ <p>These functions may use
+ <seealso marker="erts:erlang#throw/1"><c>throw</c></seealso>,
+ to return its value.
+ </p>
</desc>
</func>
<func>
- <name>Module:terminate(Reason, State, StateData) -> Ignored</name>
+ <name>Module:terminate(Reason, State, Data) -> Ignored</name>
<fsummary>Clean up before termination</fsummary>
<type>
<v>Reason = normal | shutdown | {shutdown,term()} | term()</v>
<v>State = <seealso marker="#type-state">state()</seealso></v>
- <v>StateData =
- <seealso marker="#type-state_data">
- state_data()
- </seealso>
+ <v>Data = <seealso marker="#type-data">data()</seealso>
</v>
<v>Ignored = term()</v>
</type>
@@ -1085,7 +1095,7 @@ erlang:'!' -----> Module:StateName/5
is terminating.
If it is because another callback function has returned a
stop tuple <c>{stop,Reason}</c> in
- <seealso marker="#type-state_op">StateOps</seealso>,
+ <seealso marker="#type-transition_op">Ops</seealso>,
<c>Reason</c> will have the value specified in that tuple.
If it is due to a failure, <c>Reason</c> is the error reason.
</p>
@@ -1118,11 +1128,15 @@ erlang:'!' -----> Module:StateName/5
error_logger:format/2
</seealso>.
</p>
+ <p>This function may use
+ <seealso marker="erts:erlang#throw/1"><c>throw</c></seealso>,
+ to return its value.
+ </p>
</desc>
</func>
<func>
- <name>Module:code_change(OldVsn, OldState, OldStateData, Extra) ->
+ <name>Module:code_change(OldVsn, OldState, OldData, Extra) ->
Result
</name>
<fsummary>Update the internal state during upgrade/downgrade</fsummary>
@@ -1131,12 +1145,12 @@ erlang:'!' -----> Module:StateName/5
<v>&nbsp;&nbsp;Vsn = term()</v>
<v>OldState = NewState = term()</v>
<v>Extra = term()</v>
- <v>Result = {ok,{NewState,NewStateData}} | Reason</v>
+ <v>Result = {ok,{NewState,NewData}} | Reason</v>
<v>OldState = NewState =
<seealso marker="#type-state">state()</seealso>
</v>
- <v>OldStateData = NewStateData =
- <seealso marker="#type-state_data">state_data()</seealso>
+ <v>OldData = NewData =
+ <seealso marker="#type-data">data()</seealso>
</v>
<v>Reason = term()</v>
</type>
@@ -1158,7 +1172,7 @@ erlang:'!' -----> Module:StateName/5
<c>Module</c>. If no such attribute is defined, the version
is the checksum of the BEAM file.
</p>
- <p><c>OldState</c> and <c>OldStateData</c> is the internal state
+ <p><c>OldState</c> and <c>OldData</c> is the internal state
of the <c>gen_statem</c>.
</p>
<p><c>Extra</c> is passed as-is from the <c>{advanced,Extra}</c>
@@ -1166,15 +1180,19 @@ erlang:'!' -----> Module:StateName/5
</p>
<p>If successful, the function shall return the updated
internal state in an
- <c>{ok,{NewState,NewStateData}}</c> tuple.
+ <c>{ok,{NewState,NewData}}</c> tuple.
</p>
<p>If the function returns <c>Reason</c>, the ongoing
upgrade will fail and roll back to the old release.</p>
</desc>
+ <p>This function may use
+ <seealso marker="erts:erlang#throw/1"><c>throw</c></seealso>,
+ to return its value.
+ </p>
</func>
<func>
- <name>Module:format_status(Opt, [PDict,State,StateData]) ->
+ <name>Module:format_status(Opt, [PDict,State,Data]) ->
Status
</name>
<fsummary>Optional function for providing a term describing the
@@ -1185,8 +1203,8 @@ erlang:'!' -----> Module:StateName/5
<v>State =
<seealso marker="#type-state">state()</seealso>
</v>
- <v>StateData =
- <seealso marker="#type-state_data">state_data()</seealso>
+ <v>Data =
+ <seealso marker="#type-data">data()</seealso>
</v>
<v>Key = term()</v>
<v>Value = term()</v>
@@ -1197,7 +1215,8 @@ erlang:'!' -----> Module:StateName/5
<p>This callback is optional, so callback modules need not
export it. The <c>gen_statem</c> module provides a default
implementation of this function that returns the callback
- module state.
+ module state and data. The default function will also
+ be used if this callback fails.
</p>
</note>
<p>This function is called by a <c>gen_statem</c> process when:</p>
@@ -1229,6 +1248,9 @@ erlang:'!' -----> Module:StateName/5
<p><seealso marker="#type-state"><c>State</c></seealso>
is the internal state of the <c>gen_statem</c>.
</p>
+ <p><seealso marker="#type-data"><c>Data</c></seealso>
+ is the internal server data of the <c>gen_statem</c>.
+ </p>
<p>The function should return <c>Status</c>, a term that
customises the details of the current state and status of
the <c>gen_statem</c>. There are no restrictions on the
@@ -1250,6 +1272,10 @@ erlang:'!' -----> Module:StateName/5
state representations to avoid having large state terms
printed in logfiles.
</p>
+ <p>This function may use
+ <seealso marker="erts:erlang#throw/1"><c>throw</c></seealso>,
+ to return its value.
+ </p>
</desc>
</func>
diff --git a/lib/stdlib/src/gen_statem.erl b/lib/stdlib/src/gen_statem.erl
index 8aa8afd091..1ca2e1009c 100644
--- a/lib/stdlib/src/gen_statem.erl
+++ b/lib/stdlib/src/gen_statem.erl
@@ -57,7 +57,7 @@
state_name() | % For state callback function StateName/5
term(). % For state callback function handle_event/5
-type state_name() :: atom().
--type state_data() :: term().
+-type data() :: term().
-type event_type() ::
{'call',Client :: client()} | 'cast' |
'info' | 'timeout' | 'internal'.
@@ -66,17 +66,18 @@
-type init_option() ::
{'callback_mode', callback_mode()}.
-type callback_mode() :: 'state_functions' | 'handle_event_function'.
--type state_op() ::
- %% First NewState and NewStateData are set,
- %% then all state_operations() are executed in order of
+-type transition_op() ::
+ %% First NewState and NewData are set,
+ %% then all transition_action()s are executed in order of
%% apperance. Postponing the current event is performed
- %% (iff state_option() 'postpone' is 'true').
+ %% (iff transition_option() 'postpone' is 'true').
%% Lastly pending events are processed or if there are
%% no pending events the server goes into receive
- %% or hibernate (iff state_option() 'hibernate' is 'true')
- state_option() | state_operation().
--type state_option() ::
- %% The first of each kind in the state_op() list takes precedence
+ %% or hibernate (iff transition_option() 'hibernate' is 'true')
+ transition_option() | transition_action().
+-type transition_option() ::
+ %% The last of each kind in the transition_op()
+ %% list takes precedence
'postpone' | % Postpone the current event to a different (=/=) state
{'postpone', Postpone :: boolean()} |
'hibernate' | % Hibernate the server instead of going into receive
@@ -84,10 +85,10 @@
(Timeout :: timeout()) | % {timeout,Timeout}
{'timeout', % Generate a ('timeout', Msg, ...) event after Time
Time :: timeout(), Msg :: term()}.
--type state_operation() ::
+-type transition_action() ::
%% These can occur multiple times and are executed in order
- %% of appearence in the state_op() list
- reply_operation() |
+ %% of appearence in the transition_op() list
+ reply_action() |
{'next_event', % Insert event as the next to handle
EventType :: event_type(),
EventContent :: term()} |
@@ -101,7 +102,7 @@
MonitorRef :: reference()} |
{'unlink', % Unlink and clean up mess(ages)
Id :: pid() | port()}.
--type reply_operation() ::
+-type reply_action() ::
{'reply', % Reply to a client
Client :: client(), Reply :: term()}.
-type state_callback_result() ::
@@ -109,34 +110,34 @@
Reason :: term()} |
{'stop', % Stop the server
Reason :: term(),
- NewStateData :: state_data()} |
+ NewData :: data()} |
{'stop', % Stop the server
Reason :: term(),
- Replies :: [reply_operation()] | reply_operation(),
- NewStateData :: state_data()} |
- {'next_state', % {next_state,NewState,NewStateData,[]}
+ Replies :: [reply_action()] | reply_action(),
+ NewData :: data()} |
+ {'next_state', % {next_state,NewState,NewData,[]}
NewState :: state(),
- NewStateData :: state_data()} |
+ NewData :: data()} |
{'next_state', % State transition, maybe to the same state
NewState :: state(),
- NewStateData :: state_data(),
- StateOps :: [state_op()] | state_op()} |
- {'keep_state', % {keep_state,NewStateData,[]}
- NewStateData :: state_data()} |
+ NewData :: data(),
+ Ops :: [transition_op()] | transition_op()} |
+ {'keep_state', % {keep_state,NewData,[]}
+ NewData :: data()} |
{'keep_state',
- NewStateData :: state_data(),
- StateOps :: [state_op()] | state_op()} |
+ NewData :: data(),
+ Ops :: [transition_op()] | transition_op()} |
{'keep_state_and_data'} | % {keep_state_and_data,[]}
{'keep_state_and_data',
- StateOps :: [state_op()] | state_op()}.
+ Ops :: [transition_op()] | transition_op()}.
%% The state machine init function. It is called only once and
%% the server is not running until this function has returned
%% an {ok, ...} tuple. Thereafter the state callbacks are called
%% for all events to this server.
-callback init(Args :: term()) ->
- {'ok', state(), state_data()} |
- {'ok', state(), state_data(), [state_op()|init_option()]} |
+ {'ok', state(), data()} |
+ {'ok', state(), data(), [transition_op()|init_option()]} |
'ignore' |
{'stop', Reason :: term()}.
@@ -152,7 +153,7 @@
EventContent :: term(),
PrevStateName :: state_name() | reference(),
StateName :: state_name(), % Current state
- StateData :: state_data()) ->
+ Data :: data()) ->
state_callback_result().
%%
%% Callback for callback_mode =:= handle_event_function.
@@ -164,7 +165,7 @@
EventContent :: term(),
PrevState :: state(),
State :: state(), % Current state
- StateData :: state_data()) ->
+ Data :: data()) ->
state_callback_result().
%% Clean up before the server terminates.
@@ -172,7 +173,7 @@
Reason :: 'normal' | 'shutdown' | {'shutdown', term()}
| term(),
State :: state(),
- StateData :: state_data()) ->
+ Data :: data()) ->
any().
%% Note that the new code can expect to get an OldState from
@@ -181,9 +182,9 @@
-callback code_change(
OldVsn :: term() | {'down', term()},
OldState :: state(),
- OldStateData :: state_data(),
+ OldData :: data(),
Extra :: term()) ->
- {ok, {NewState :: state(), NewStateData :: state_data()}}.
+ {ok, {NewState :: state(), NewData :: data()}}.
%% Format the callback module state in some sensible that is
%% often condensed way. For StatusOption =:= 'normal' the perferred
@@ -193,7 +194,7 @@
StatusOption,
[ [{Key :: term(), Value :: term()}] |
state() |
- state_data()]) ->
+ data()]) ->
Status :: term() when
StatusOption :: 'normal' | 'terminate'.
@@ -264,38 +265,38 @@ event_type(Type) ->
-type start_opt() ::
debug_opt()
| {'timeout', Time :: timeout()}
- | {'spawn_opt', SOpts :: [proc_lib:spawn_option()]}.
+ | {'spawn_opt', [proc_lib:spawn_option()]}.
-type start_ret() :: {'ok', pid()} | 'ignore' | {'error', term()}.
%% Start a state machine
-spec start(
- Module :: module(), Args :: term(), Options :: [start_opt()]) ->
+ Module :: module(), Args :: term(), Opts :: [start_opt()]) ->
start_ret().
-start(Module, Args, Options) ->
- gen:start(?MODULE, nolink, Module, Args, Options).
+start(Module, Args, Opts) ->
+ gen:start(?MODULE, nolink, Module, Args, Opts).
%%
-spec start(
ServerName :: server_name(),
- Module :: module(), Args :: term(), Options :: [start_opt()]) ->
+ Module :: module(), Args :: term(), Opts :: [start_opt()]) ->
start_ret().
-start(ServerName, Module, Args, Options) ->
- gen:start(?MODULE, nolink, ServerName, Module, Args, Options).
+start(ServerName, Module, Args, Opts) ->
+ gen:start(?MODULE, nolink, ServerName, Module, Args, Opts).
%% Start and link to a state machine
-spec start_link(
- Module :: module(), Args :: term(), Options :: [start_opt()]) ->
+ Module :: module(), Args :: term(), Opts :: [start_opt()]) ->
start_ret().
-start_link(Module, Args, Options) ->
- gen:start(?MODULE, link, Module, Args, Options).
+start_link(Module, Args, Opts) ->
+ gen:start(?MODULE, link, Module, Args, Opts).
%%
-spec start_link(
ServerName :: server_name(),
- Module :: module(), Args :: term(), Options :: [start_opt()]) ->
+ Module :: module(), Args :: term(), Opts :: [start_opt()]) ->
start_ret().
-start_link(ServerName, Module, Args, Options) ->
- gen:start(?MODULE, link, ServerName, Module, Args, Options).
+start_link(ServerName, Module, Args, Opts) ->
+ gen:start(?MODULE, link, ServerName, Module, Args, Opts).
%% Stop a state machine
-spec stop(ServerRef :: server_ref()) -> ok.
@@ -389,7 +390,7 @@ call(ServerRef, Request, Timeout) ->
end.
%% Reply from a state machine callback to whom awaits in call/2
--spec reply([reply_operation()] | reply_operation()) -> ok.
+-spec reply([reply_action()] | reply_action()) -> ok.
reply({reply,{_To,_Tag}=Client,Reply}) ->
reply(Client, Reply);
reply(Replies) when is_list(Replies) ->
@@ -411,39 +412,39 @@ reply({To,Tag}, Reply) ->
%% started by proc_lib into a state machine using
%% the same arguments as you would have returned from init/1
-spec enter_loop(
- Module :: module(), Options :: [debug_opt()],
- State :: state(), StateData :: state_data()) ->
+ Module :: module(), Opts :: [debug_opt()],
+ State :: state(), Data :: data()) ->
no_return().
-enter_loop(Module, Options, State, StateData) ->
- enter_loop(Module, Options, State, StateData, self()).
+enter_loop(Module, Opts, State, Data) ->
+ enter_loop(Module, Opts, State, Data, self()).
%%
-spec enter_loop(
- Module :: module(), Options :: [debug_opt()],
- State :: state(), StateData :: state_data(),
- Server_or_StateOps ::
- server_name() | pid() | [state_op()|init_option()]) ->
+ Module :: module(), Opts :: [debug_opt()],
+ State :: state(), Data :: data(),
+ Server_or_Ops ::
+ server_name() | pid() | [transition_op()|init_option()]) ->
no_return().
-enter_loop(Module, Options, State, StateData, Server_or_StateOps) ->
+enter_loop(Module, Opts, State, Data, Server_or_Ops) ->
if
- is_list(Server_or_StateOps) ->
+ is_list(Server_or_Ops) ->
enter_loop(
- Module, Options, State, StateData,
- self(), Server_or_StateOps);
+ Module, Opts, State, Data,
+ self(), Server_or_Ops);
true ->
enter_loop(
- Module, Options, State, StateData,
- Server_or_StateOps, [])
+ Module, Opts, State, Data,
+ Server_or_Ops, [])
end.
%%
-spec enter_loop(
- Module :: module(), Options :: [debug_opt()],
- State :: state(), StateData :: state_data(),
+ Module :: module(), Opts :: [debug_opt()],
+ State :: state(), Data :: data(),
Server :: server_name() | pid(),
- StateOps :: [state_op()|init_option()]) ->
+ Ops :: [transition_op()|init_option()]) ->
no_return().
-enter_loop(Module, Options, State, StateData, Server, StateOps) ->
+enter_loop(Module, Opts, State, Data, Server, Ops) ->
Parent = gen:get_parent(),
- enter(Module, Options, State, StateData, Server, StateOps, Parent).
+ enter(Module, Opts, State, Data, Server, Ops, Parent).
%%---------------------------------------------------------------------------
%% API helpers
@@ -465,29 +466,29 @@ do_send(Proc, Msg) ->
end.
%% Here init_it and all enter_loop functions converge
-enter(Module, Options, State, StateData, Server, InitOps, Parent) ->
+enter(Module, Opts, State, Data, Server, InitOps, Parent) ->
Name = gen:get_proc_name(Server),
- Debug = gen:debug_options(Name, Options),
+ Debug = gen:debug_options(Name, Opts),
PrevState = undefined,
S = #{
callback_mode => state_functions,
module => Module,
name => Name,
prev_state => PrevState,
- state => PrevState, % Will be discarded by loop_event_state_ops
- state_data => StateData,
+ state => PrevState, % Will be discarded by loop_event_transition_ops
+ data => Data,
timer => undefined,
postponed => [],
hibernate => false},
case collect_init_options(InitOps) of
- {CallbackMode,StateOps} ->
- loop_event_state_ops(
+ {CallbackMode,Ops} ->
+ loop_event_transition_ops(
Parent, Debug,
S#{callback_mode := CallbackMode},
[],
{event,undefined}, % Will be discarded by {postpone,false}
- PrevState, State, StateData,
- StateOps++[{postpone,false}]);
+ PrevState, State, Data,
+ Ops++[{postpone,false}]);
[Reason] ->
?TERMINATE(Reason, Debug, S, [])
end.
@@ -495,13 +496,13 @@ enter(Module, Options, State, StateData, Server, InitOps, Parent) ->
%%%==========================================================================
%%% gen callbacks
-init_it(Starter, Parent, ServerRef, Module, Args, Options) ->
+init_it(Starter, Parent, ServerRef, Module, Args, Opts) ->
try Module:init(Args) of
Result ->
- init_result(Starter, Parent, ServerRef, Module, Result, Options)
+ init_result(Starter, Parent, ServerRef, Module, Result, Opts)
catch
Result ->
- init_result(Starter, Parent, ServerRef, Module, Result, Options);
+ init_result(Starter, Parent, ServerRef, Module, Result, Opts);
Class:Reason ->
gen:unregister_name(ServerRef),
proc_lib:init_ack(Starter, {error,Reason}),
@@ -511,18 +512,14 @@ init_it(Starter, Parent, ServerRef, Module, Args, Options) ->
%%---------------------------------------------------------------------------
%% gen callbacks helpers
-init_result(Starter, Parent, ServerRef, Module, Result, Options) ->
+init_result(Starter, Parent, ServerRef, Module, Result, Opts) ->
case Result of
- {ok,State,StateData} ->
+ {ok,State,Data} ->
proc_lib:init_ack(Starter, {ok,self()}),
- enter(
- Module, Options, State, StateData, ServerRef,
- [], Parent);
- {ok,State,StateData,StateOps} ->
+ enter(Module, Opts, State, Data, ServerRef, [], Parent);
+ {ok,State,Data,Ops} ->
proc_lib:init_ack(Starter, {ok,self()}),
- enter(
- Module, Options, State, StateData, ServerRef,
- StateOps, Parent);
+ enter(Module, Opts, State, Data, ServerRef, Ops, Parent);
{stop,Reason} ->
gen:unregister_name(ServerRef),
proc_lib:init_ack(Starter, {error,Reason}),
@@ -549,32 +546,32 @@ system_terminate(Reason, _Parent, Debug, S) ->
system_code_change(
#{module := Module,
state := State,
- state_data := StateData} = S,
+ data := Data} = S,
_Mod, OldVsn, Extra) ->
case
- try Module:code_change(OldVsn, State, StateData, Extra)
+ try Module:code_change(OldVsn, State, Data, Extra)
catch
Result -> Result
end
of
- {ok,{NewState,NewStateData}} ->
+ {ok,{NewState,NewData}} ->
{ok,
S#{
state := NewState,
- state_data := NewStateData}};
+ data := NewData}};
Error ->
Error
end.
-system_get_state(#{state := State, state_data := StateData}) ->
- {ok,{State,StateData}}.
+system_get_state(#{state := State, data := Data}) ->
+ {ok,{State,Data}}.
system_replace_state(
StateFun,
#{state := State,
- state_data := StateData} = S) ->
- {NewState,NewStateData} = Result = StateFun({State,StateData}),
- {ok,Result,S#{state := NewState, state_data := NewStateData}}.
+ data := Data} = S) ->
+ {NewState,NewData} = Result = StateFun({State,Data}),
+ {ok,Result,S#{state := NewState, data := NewData}}.
format_status(
Opt,
@@ -642,7 +639,7 @@ wakeup_from_hibernate(Parent, Debug, S) ->
loop_receive(Parent, Debug, S).
%%%==========================================================================
-%%% STate Machine engine implementation of proc_lib/gen server
+%%% State Machine engine implementation of proc_lib/gen server
%% Server loop, consists of all loop* functions
%% and some detours through sys and proc_lib
@@ -717,7 +714,7 @@ loop_events(
module := Module,
prev_state := PrevState,
state := State,
- state_data := StateData} = S,
+ data := Data} = S,
[{Type,Content} = Event|Events] = Q, Timer) ->
_ = (Timer =/= undefined) andalso
cancel_timer(Timer),
@@ -728,7 +725,7 @@ loop_events(
state_functions ->
State
end,
- try Module:Func(Type, Content, PrevState, State, StateData) of
+ try Module:Func(Type, Content, PrevState, State, Data) of
Result ->
loop_event_result(
Parent, Debug, S, Events, Event, Result)
@@ -741,7 +738,7 @@ loop_events(
%% of calling a nonexistent state function
case erlang:get_stacktrace() of
[{Module,Func,
- [Type,Content,PrevState,State,StateData]=Args,
+ [Type,Content,PrevState,State,Data]=Args,
_}
|Stacktrace] ->
terminate(
@@ -760,18 +757,18 @@ loop_events(
%% Interpret all callback return value variants
loop_event_result(
Parent, Debug,
- #{state := State, state_data := StateData} = S,
+ #{state := State, data := Data} = S,
Events, Event, Result) ->
case Result of
{stop,Reason} ->
?TERMINATE(Reason, Debug, S, [Event|Events]);
- {stop,Reason,NewStateData} ->
+ {stop,Reason,NewData} ->
?TERMINATE(
Reason, Debug,
- S#{state_data := NewStateData},
+ S#{data := NewData},
[Event|Events]);
- {stop,Reason,Reply,NewStateData} ->
- NewS = S#{state_data := NewStateData},
+ {stop,Reason,Reply,NewData} ->
+ NewS = S#{data := NewData},
Q = [Event|Events],
Replies =
if
@@ -785,43 +782,43 @@ loop_event_result(
exit, Reason, ?STACKTRACE(), Debug, NewS, Q, Replies),
%% Since we got back here Replies was bad
?TERMINATE(
- {bad_return_value,{stop,Reason,BadReplies,NewStateData}},
+ {bad_return_value,{stop,Reason,BadReplies,NewData}},
Debug, NewS, Q);
- {next_state,NewState,NewStateData} ->
- loop_event_state_ops(
+ {next_state,NewState,NewData} ->
+ loop_event_transition_ops(
Parent, Debug, S, Events, Event,
- State, NewState, NewStateData, []);
- {next_state,NewState,NewStateData,StateOps}
- when is_list(StateOps) ->
- loop_event_state_ops(
+ State, NewState, NewData, []);
+ {next_state,NewState,NewData,Ops}
+ when is_list(Ops) ->
+ loop_event_transition_ops(
Parent, Debug, S, Events, Event,
- State, NewState, NewStateData, StateOps);
- {keep_state,NewStateData} ->
- loop_event_state_ops(
+ State, NewState, NewData, Ops);
+ {keep_state,NewData} ->
+ loop_event_transition_ops(
Parent, Debug, S, Events, Event,
- State, State, NewStateData, []);
- {keep_state,NewStateData,StateOps} ->
- loop_event_state_ops(
+ State, State, NewData, []);
+ {keep_state,NewData,Ops} ->
+ loop_event_transition_ops(
Parent, Debug, S, Events, Event,
- State, State, NewStateData, StateOps);
+ State, State, NewData, Ops);
{keep_state_and_data} ->
- loop_event_state_ops(
+ loop_event_transition_ops(
Parent, Debug, S, Events, Event,
- State, State, StateData, []);
- {keep_state_and_data,StateOps} ->
- loop_event_state_ops(
+ State, State, Data, []);
+ {keep_state_and_data,Ops} ->
+ loop_event_transition_ops(
Parent, Debug, S, Events, Event,
- State, State, StateData, StateOps);
+ State, State, Data, Ops);
_ ->
?TERMINATE(
{bad_return_value,Result}, Debug, S, [Event|Events])
end.
-loop_event_state_ops(
+loop_event_transition_ops(
Parent, Debug0, #{postponed := P0} = S, Events, Event,
- State, NewState, NewStateData, StateOps) ->
- case collect_state_options(StateOps) of
- {Postpone,Hibernate,Timeout,Operations} ->
+ State, NewState, NewData, Ops) ->
+ case collect_transition_options(Ops) of
+ {Postpone,Hibernate,Timeout,Actions} ->
P1 = % Move current event to postponed if Postpone
case Postpone of
true ->
@@ -837,8 +834,8 @@ loop_event_state_ops(
{lists:reverse(P1, Events),[]}
end,
%%
- case process_state_operations(
- Operations, Debug0, S, Q2, P2) of
+ case process_transition_actions(
+ Actions, Debug0, S, Q2, P2) of
{Debug,Q3,P} ->
NewDebug =
sys_debug(
@@ -865,7 +862,7 @@ loop_event_state_ops(
S#{
prev_state := State,
state := NewState,
- state_data := NewStateData,
+ data := NewData,
timer := Timer,
hibernate := Hibernate,
postponed := P},
@@ -892,92 +889,96 @@ collect_init_options(InitOps) ->
collect_init_options([InitOps], state_functions, [])
end.
%% Keep the last of each kind
-collect_init_options([], CallbackMode, StateOps) ->
- {CallbackMode,lists:reverse(StateOps)};
-collect_init_options([InitOp|InitOps] = IOIOs, CallbackMode, StateOps) ->
+collect_init_options([], CallbackMode, Ops) ->
+ {CallbackMode,lists:reverse(Ops)};
+collect_init_options(
+ [InitOp|InitOps] = AllInitOps, CallbackMode, Ops) ->
case InitOp of
{callback_mode,Mode}
when Mode =:= state_functions;
Mode =:= handle_event_function ->
- collect_init_options(InitOps, Mode, StateOps);
+ collect_init_options(InitOps, Mode, Ops);
{callback_mode,_} ->
- [{bad_init_ops,IOIOs}];
- _ -> % Collect others as StateOps
+ [{bad_init_ops,AllInitOps}];
+ _ -> % Collect others as Ops
collect_init_options(
- InitOps, CallbackMode, [InitOp|StateOps])
+ InitOps, CallbackMode, [InitOp|Ops])
end.
-collect_state_options(StateOps) ->
+collect_transition_options(Ops) ->
if
- is_list(StateOps) ->
- collect_state_options(StateOps, false, false, undefined, []);
+ is_list(Ops) ->
+ collect_transition_options(
+ Ops, false, false, undefined, []);
true ->
- collect_state_options([StateOps], false, false, undefined, [])
+ collect_transition_options(
+ [Ops], false, false, undefined, [])
end.
%% Keep the last of each kind
-collect_state_options(
- [], Postpone, Hibernate, Timeout, Operations) ->
- {Postpone,Hibernate,Timeout,lists:reverse(Operations)};
-collect_state_options(
- [StateOp|StateOps] = SOSOs, Postpone, Hibernate, Timeout, Operations) ->
- case StateOp of
+collect_transition_options(
+ [], Postpone, Hibernate, Timeout, Actions) ->
+ {Postpone,Hibernate,Timeout,lists:reverse(Actions)};
+collect_transition_options(
+ [Op|Ops] = AllOps, Postpone, Hibernate, Timeout, Actions) ->
+ case Op of
postpone ->
- collect_state_options(
- StateOps, true, Hibernate, Timeout, Operations);
+ collect_transition_options(
+ Ops, true, Hibernate, Timeout, Actions);
{postpone,NewPostpone} when is_boolean(NewPostpone) ->
- collect_state_options(
- StateOps, NewPostpone, Hibernate, Timeout, Operations);
+ collect_transition_options(
+ Ops, NewPostpone, Hibernate, Timeout, Actions);
{postpone,_} ->
- [{bad_state_ops,SOSOs}];
+ [{bad_ops,AllOps}];
hibernate ->
- collect_state_options(
- StateOps, Postpone, true, Timeout, Operations);
+ collect_transition_options(
+ Ops, Postpone, true, Timeout, Actions);
{hibernate,NewHibernate} when is_boolean(NewHibernate) ->
- collect_state_options(
- StateOps, Postpone, NewHibernate, Timeout, Operations);
+ collect_transition_options(
+ Ops, Postpone, NewHibernate, Timeout, Actions);
{hibernate,_} ->
- [{bad_state_ops,SOSOs}];
+ [{bad_ops,AllOps}];
{timeout,infinity,_} -> % Ignore since it will never time out
- collect_state_options(
- StateOps, Postpone, Hibernate, undefined, Operations);
+ collect_transition_options(
+ Ops, Postpone, Hibernate, undefined, Actions);
{timeout,Time,_} = NewTimeout when is_integer(Time), Time >= 0 ->
- collect_state_options(
- StateOps, Postpone, Hibernate, NewTimeout, Operations);
+ collect_transition_options(
+ Ops, Postpone, Hibernate, NewTimeout, Actions);
{timeout,_,_} ->
- [{bad_state_ops,SOSOs}];
- _ -> % Collect others as operations
- collect_state_options(
- StateOps, Postpone, Hibernate, Timeout, [StateOp|Operations])
+ [{bad_ops,AllOps}];
+ _ -> % Collect others as actions
+ collect_transition_options(
+ Ops, Postpone, Hibernate, Timeout, [Op|Actions])
end.
-process_state_operations([], Debug, _S, Q, P) ->
+process_transition_actions([], Debug, _S, Q, P) ->
{Debug,Q,P};
-process_state_operations([Operation|Operations] = OOs, Debug, S, Q, P) ->
- case Operation of
+process_transition_actions(
+ [Action|Actions] = AllActions, Debug, S, Q, P) ->
+ case Action of
{reply,{_To,_Tag}=Client,Reply} ->
NewDebug = do_reply(Debug, S, Client, Reply),
- process_state_operations(Operations, NewDebug, S, Q, P);
+ process_transition_actions(Actions, NewDebug, S, Q, P);
{next_event,Type,Content} ->
case event_type(Type) of
true ->
- process_state_operations(
- Operations, Debug, S, [{Type,Content}|Q], P);
+ process_transition_actions(
+ Actions, Debug, S, [{Type,Content}|Q], P);
false ->
- [{bad_state_ops,OOs},Debug]
+ [{bad_ops,AllActions},Debug]
end;
_ ->
- %% All others are remove operations
- case remove_fun(Operation) of
+ %% All others are remove actions
+ case remove_fun(Action) of
false ->
- process_state_operations(
- Operations, Debug, S, Q, P);
+ process_transition_actions(
+ Actions, Debug, S, Q, P);
undefined ->
- [{bad_state_ops,OOs},Debug];
+ [{bad_ops,AllActions},Debug];
RemoveFun when is_function(RemoveFun, 2) ->
case remove_event(RemoveFun, Q, P) of
{NewQ,NewP} ->
- process_state_operations(
- Operations, Debug, S, NewQ, NewP);
+ process_transition_actions(
+ Actions, Debug, S, NewQ, NewP);
Error ->
Error ++ [Debug]
end;
@@ -1023,7 +1024,8 @@ remove_event(RemoveFun, Q, P) ->
[Class,Reason,erlang:get_stacktrace()]
end.
-%% Do the given state operation and create an event removal predicate fun()
+%% Do the given transition action and create
+%% an event removal predicate fun()
remove_fun({remove_event,Type,Content}) ->
fun (T, C) when T =:= Type, C =:= Content -> true;
(_, _) -> false
@@ -1104,9 +1106,9 @@ cancel_timer(TimerRef) ->
terminate(
Class, Reason, Stacktrace, Debug,
#{module := Module,
- state := State, state_data := StateData} = S,
+ state := State, data := Data} = S,
Q) ->
- try Module:terminate(Reason, State, StateData) of
+ try Module:terminate(Reason, State, Data) of
_ -> ok
catch
_ -> ok;
@@ -1137,7 +1139,7 @@ error_info(
Class, Reason, Stacktrace, Debug,
#{name := Name, callback_mode := CallbackMode,
state := State, postponed := P},
- Q, FmtStateData) ->
+ Q, FmtData) ->
{FixedReason,FixedStacktrace} =
case Stacktrace of
[{M,F,Args,_}|ST]
@@ -1190,7 +1192,7 @@ error_info(
[Event|_] ->
[Event]
end] ++
- [FmtStateData,Class,FixedReason,
+ [FmtData,Class,FixedReason,
State,CallbackMode,length(Q),length(P)] ++
case FixedStacktrace of
[] ->
@@ -1205,22 +1207,22 @@ error_info(
%% Call Module:format_status/2 or return a default value
format_status(
Opt, PDict,
- #{module := Module, state := State, state_data := StateData}) ->
+ #{module := Module, state := State, data := Data}) ->
case erlang:function_exported(Module, format_status, 2) of
true ->
- try Module:format_status(Opt, [PDict,State,StateData])
+ try Module:format_status(Opt, [PDict,State,Data])
catch
Result -> Result;
_:_ ->
- format_status_default(Opt, State, StateData)
+ format_status_default(Opt, State, Data)
end;
false ->
- format_status_default(Opt, State, StateData)
+ format_status_default(Opt, State, Data)
end.
%% The default Module:format_status/2
-format_status_default(Opt, State, StateData) ->
- SSD = {State,StateData},
+format_status_default(Opt, State, Data) ->
+ SSD = {State,Data},
case Opt of
terminate ->
SSD;
diff --git a/lib/stdlib/test/gen_statem_SUITE.erl b/lib/stdlib/test/gen_statem_SUITE.erl
index 4ac4acd189..65a8d35645 100644
--- a/lib/stdlib/test/gen_statem_SUITE.erl
+++ b/lib/stdlib/test/gen_statem_SUITE.erl
@@ -573,10 +573,10 @@ call_format_status(Config) when is_list(Config) ->
error_format_status(Config) when is_list(Config) ->
error_logger_forwarder:register(),
OldFl = process_flag(trap_exit, true),
- StateData = "called format_status",
+ Data = "called format_status",
{ok,Pid} =
gen_statem:start(
- ?MODULE, start_arg(Config, {state_data,StateData}), []),
+ ?MODULE, start_arg(Config, {data,Data}), []),
%% bad return value in the gen_statem loop
{{bad_return_value,badreturn},_} =
?EXPECT_FAILURE(gen_statem:call(Pid, badreturn), Reason),
@@ -585,7 +585,7 @@ error_format_status(Config) when is_list(Config) ->
{Pid,
"** State machine"++_,
[Pid,{{call,_},badreturn},
- {formatted,idle,StateData},
+ {formatted,idle,Data},
exit,{bad_return_value,badreturn}|_]}} ->
ok;
Other when is_tuple(Other), element(1, Other) =:= error ->
@@ -609,10 +609,10 @@ error_format_status(Config) when is_list(Config) ->
terminate_crash_format(Config) when is_list(Config) ->
error_logger_forwarder:register(),
OldFl = process_flag(trap_exit, true),
- StateData = crash_terminate,
+ Data = crash_terminate,
{ok,Pid} =
gen_statem:start(
- ?MODULE, start_arg(Config, {state_data,StateData}), []),
+ ?MODULE, start_arg(Config, {data,Data}), []),
stop_it(Pid),
Self = self(),
receive
@@ -621,7 +621,7 @@ terminate_crash_format(Config) when is_list(Config) ->
"** State machine"++_,
[Pid,
{{call,{Self,_}},stop},
- {formatted,idle,StateData},
+ {formatted,idle,Data},
exit,{crash,terminate}|_]}} ->
ok;
Other when is_tuple(Other), element(1, Other) =:= error ->
@@ -647,7 +647,7 @@ get_state(Config) when is_list(Config) ->
State = self(),
{ok,Pid} =
gen_statem:start(
- ?MODULE, start_arg(Config, {state_data,State}), []),
+ ?MODULE, start_arg(Config, {data,State}), []),
{idle,State} = sys:get_state(Pid),
{idle,State} = sys:get_state(Pid, 5000),
stop_it(Pid),
@@ -656,7 +656,7 @@ get_state(Config) when is_list(Config) ->
%% already checked by the previous test)
{ok,Pid2} =
gen_statem:start(
- {local,gstm}, ?MODULE, start_arg(Config, {state_data,State}), []),
+ {local,gstm}, ?MODULE, start_arg(Config, {data,State}), []),
{idle,State} = sys:get_state(gstm),
{idle,State} = sys:get_state(gstm, 5000),
stop_it(Pid2),
@@ -664,7 +664,7 @@ get_state(Config) when is_list(Config) ->
%% check that get_state works when pid is sys suspended
{ok,Pid3} =
gen_statem:start(
- ?MODULE, start_arg(Config, {state_data,State}), []),
+ ?MODULE, start_arg(Config, {data,State}), []),
{idle,State} = sys:get_state(Pid3),
ok = sys:suspend(Pid3),
{idle,State} = sys:get_state(Pid3, 5000),
@@ -676,7 +676,7 @@ replace_state(Config) when is_list(Config) ->
State = self(),
{ok, Pid} =
gen_statem:start(
- ?MODULE, start_arg(Config, {state_data,State}), []),
+ ?MODULE, start_arg(Config, {data,State}), []),
{idle,State} = sys:get_state(Pid),
NState1 = "replaced",
Replace1 = fun({StateName, _}) -> {StateName,NState1} end,
@@ -1124,8 +1124,8 @@ init(hiber) ->
{ok,hiber_idle,[]};
init(hiber_now) ->
{ok,hiber_idle,[],[hibernate]};
-init({state_data, StateData}) ->
- {ok,idle,StateData};
+init({data, Data}) ->
+ {ok,idle,Data};
init({init_ops,Arg,InitOps}) ->
case init(Arg) of
{ok,State,Data,Ops} ->
@@ -1136,7 +1136,7 @@ init({init_ops,Arg,InitOps}) ->
Other
end;
init([]) ->
- {ok,idle,state_data}.
+ {ok,idle,data}.
terminate(_, _State, crash_terminate) ->
exit({crash,terminate});
@@ -1362,20 +1362,20 @@ unwrap_state(State) ->
wrap_result(Result) ->
case Result of
- {next_state,NewState,NewStateData} ->
- {next_state,[NewState],NewStateData};
- {next_state,NewState,NewStateData,StateOps} ->
- {next_state,[NewState],NewStateData,StateOps};
+ {next_state,NewState,NewData} ->
+ {next_state,[NewState],NewData};
+ {next_state,NewState,NewData,StateOps} ->
+ {next_state,[NewState],NewData,StateOps};
Other ->
Other
end.
-code_change(_OldVsn, State, StateData, _Extra) ->
- {ok,State,StateData}.
+code_change(_OldVsn, State, Data, _Extra) ->
+ {ok,State,Data}.
-format_status(terminate, [_Pdict,State,StateData]) ->
- {formatted,State,StateData};
-format_status(normal, [_Pdict,_State,_StateData]) ->
+format_status(terminate, [_Pdict,State,Data]) ->
+ {formatted,State,Data};
+format_status(normal, [_Pdict,_State,_Data]) ->
[format_status_called].