A behaviour module for implementing a state machine.
Two callback modes are supported. One for a finite state
machine like
A generic state machine process (
A
gen_statem module Callback module ----------------- --------------- gen_statem:start gen_statem:start_link -----> Module:init/1 gen_statem:stop -----> Module:terminate/2 gen_statem:call gen_statem:cast erlang:send erlang:'!' -----> Module:StateName/5 Module:handle_event/5 - -----> Module:terminate/3 - -----> Module:code_change/3
Events are of different
If a callback function fails or returns a bad value,
the
The "state function" for a specific
When
When
Any state name or any state value (depending on
The
The
The
Inserting an event replaces the trick of calling your own
state handling functions that you often would have to
resort to in e.g
A
Note that a
Unless otherwise stated, all functions in this module fail if
the specified
The
Name specification to use when starting
a
Server specification to use when addressing
a
It can be:
Debug option that can be used when starting
a
For every entry in
Options that can be used when starting
a
Return value from the start functions for_example
Destination to use when replying through for example the
After a state change (
If
A term in which the state machine implementation
should store any server data it needs. The difference between
this and the
External events are of 3 different type:
A
The predicate may not use a throw exception to return its result.
Either a
These may be returned from the
The processing order for a state change is:
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.
The state transition actions are executed
in the containing list order. This matters
for
Reply to a caller waiting for a reply in
Creates a
The
If the option
If the option
If the option
Using the spawn option
If the
If
Creates a stand-alone
See
The same as
Orders the
This function returns
If the process does not exist, a
Makes a synchronous call to the
A
To avoid getting a late reply in the caller's
inbox this function spawns a proxy process that
does the call. A late reply gets delivered to the
dead proxy process hence gets discarded. This is
less efficient than using
The call may fail for example if the
Sends an asynchronous event to the
This function can be used by a
A reply sent with this function will not be visible
in
The same as
If
Otherwise the same as
Makes an the calling process become a
This function is useful when a more complex initialization
procedure is needed than
the
Failure: If the calling process was not started by a
The following functions should be exported from a
Whenever a
If the initialization is successful, the function should
return
The
If something goes wrong during the initialization
the function should return
This function may use
Whenever a
If
If this function returns with a new state that
does not match equal (
See
These functions may use
This function is called by a
If the
Even if the
Otherwise, the
Note that for any other reason than
This function may use
This function is called by a
In the case of an upgrade,
If successful, the function shall return the updated
internal state in an
If the function returns
This function may use
This callback is optional, so a callback module need not
export it. The
This function is called by a
This function is useful for customising the form and
appearance of the
The function should return
One use for this function is to return compact alternative state representations to avoid having large state terms printed in logfiles. Another is to hide sensitive data from being written to the error log.
This function may use