From f4de3f5887be010db178a178e1f20027f3e5d22b Mon Sep 17 00:00:00 2001
From: Raimo Niskanen
- The "state function" for a specific
+ The "state callback" for a specific
The
- The
The
If you in
callback_mode() -> handle_event_function.
-%%% State function(s)
+%%% state callback(s)
handle_event({call,From}, push, off, Data) ->
%% Go to 'on', increment count and reply
@@ -482,6 +482,10 @@ handle_event(_, _, State, Data) ->
+ If the
+ callback mode
+ is handle_event_function ,
+ the state can be any term.
After a state change (NextState =/= State ),
all postponed events are retried.
@@ -495,6 +499,8 @@ handle_event(_, _, State, Data) ->
callback mode
is state_functions ,
the state must be of this type.
+ After a state change (NextState =/= State ),
+ all postponed events are retried.
@@ -592,11 +598,11 @@ handle_event(_, _, State, Data) ->
returns a list containing state_enter ,
the gen_statem engine will, at every state change,
call the
- state function
+ state callback
with arguments (enter, OldState, Data) .
This may look like an event but is really a call
- performed after the previous state function returned
- and before any event is delivered to the new state function.
+ performed after the previous state callback returned
+ and before any event is delivered to the new state callback.
See
Module:StateName/3
and
@@ -666,19 +672,19 @@ handle_event(_, _, State, Data) ->
If the state changes or is the initial state, and
state enter calls
are used, the gen_statem calls
- the new state function with arguments
+ the new state callback with arguments
(enter, OldState, Data) .
Any
actions
returned from this call are handled as if they were
appended to the actions
- returned by the state function that changed states.
+ returned by the state callback that changed states.
-
If there are enqueued events the (possibly new)
- state function
+ state callback
is called with the oldest enqueued event,
and we start again from the top of this list.
@@ -691,7 +697,7 @@ handle_event(_, _, State, Data) ->
event_timeout()
are handled. This may lead to a time-out zero event
being generated to the
- state function
+ state callback
and we start again from the top of this list.
@@ -707,7 +713,7 @@ handle_event(_, _, State, Data) ->
the next incoming message awakens the gen_statem ,
but if it is a system event it goes right back into hibernation.
When a new message arrives the
- state function
+ state callback
is called with the corresponding event,
and we start again from the top of this list.
@@ -806,7 +812,7 @@ handle_event(_, _, State, Data) ->
These state transition actions can be invoked by
returning them from the
- state function
+ state callback
when it is called with an
event ,
from
@@ -870,7 +876,7 @@ handle_event(_, _, State, Data) ->
These state transition actions can be invoked by
returning them from the
- state function , from
+ state callback , from
Module:init/1
or by giving them to
enter_loop/5,6 .
@@ -903,7 +909,7 @@ handle_event(_, _, State, Data) ->
Short for {timeout,Timeout,Timeout} , that is,
the time-out message is the time-out time.
This form exists to make the
- state function
+ state callback
return value {next_state,NextState,NewData,Timeout}
allowed like for gen_fsm 's
Module:StateName/2 .
@@ -936,7 +942,7 @@ handle_event(_, _, State, Data) ->
This state transition action can be invoked by
returning it from the
- state function , from
+ state callback , from
Module:init/1
or by giving it to
enter_loop/5,6 .
@@ -947,7 +953,7 @@ handle_event(_, _, State, Data) ->
From must be the term from argument
{call,From }
in a call to a
- state function .
+ state callback .
Note that using this action from
@@ -956,77 +962,48 @@ handle_event(_, _, State, Data) ->
enter_loop/5,6
would be weird on the border of whichcraft
since there has been no earlier call to a
- state function
+ state callback
in this server.
-
+
-
- next_state
- -
-
- The gen_statem does a state transition to
- NextStateName
- (which can be the same as the current state),
- sets NewData ,
- and executes all Actions .
-
-
-
- All these terms are tuples or atoms and this property
- will hold in any future version of gen_statem .
+ State is the current state
+ and it can not be changed since the state callback
+ was called with a
+ state enter call .
-
-
-
-
-
next_state
-
The gen_statem does a state transition to
- NextStateName
- (which can be the same as the current state),
+ State , which has to be
+ the current state,
sets NewData ,
and executes all Actions .
-
- All these terms are tuples or atoms and this property
- will hold in any future version of gen_statem .
-
-
+
-
- next_state
- -
-
- The gen_statem does a state transition to
- NextState
- (which can be the same as the current state),
- sets NewData ,
- and executes all Actions .
-
-
-
- All these terms are tuples or atoms and this property
- will hold in any future version of gen_statem .
+ StateType is
+ state_name()
+ if
+ callback mode
+ is state_functions , or
+ state()
+ if
+ callback mode
+ is handle_event_function .
-
-
-
-
-
next_state
-
@@ -1039,48 +1016,20 @@ handle_event(_, _, State, Data) ->
-
- All these terms are tuples or atoms and this property
- will hold in any future version of gen_statem .
-
-
+
-
- keep_state
- -
-
- The gen_statem keeps the current state, or
- does a state transition to the current state if you like,
- sets NewData ,
- and executes all Actions .
- This is the same as
- {next_state,CurrentState,NewData ,Actions } .
-
-
- keep_state_and_data
- -
-
- The gen_statem keeps the current state or
- does a state transition to the current state if you like,
- keeps the current server data,
- and executes all Actions .
- This is the same as
- {next_state,CurrentState,CurrentData,Actions } .
-
-
-
- All these terms are tuples or atoms and this property
- will hold in any future version of gen_statem .
+ ActionType is
+ enter_action()
+ if the state callback was called with a
+ state enter call
+ and
+ action()
+ if the state callback was called with an event.
-
-
-
-
-
keep_state
-
@@ -1104,17 +1053,6 @@ handle_event(_, _, State, Data) ->
{next_state,CurrentState,CurrentData,Actions } .
-
-
- All these terms are tuples or atoms and this property
- will hold in any future version of gen_statem .
-
-
-
-
-
-
-
stop
-
@@ -1155,14 +1093,14 @@ handle_event(_, _, State, Data) ->
by sending a request
and waiting until its reply arrives.
The gen_statem calls the
- state function with
+ state callback with
event_type()
{call,From} and event content
Request .
A Reply is generated when a
- state function
+ state callback
returns with
{reply,From,Reply } as one
action() ,
@@ -1227,7 +1165,7 @@ handle_event(_, _, State, Data) ->
ignoring if the destination node or gen_statem
does not exist.
The gen_statem calls the
- state function with
+ state callback with
event_type()
cast and event content
Msg .
@@ -1341,18 +1279,18 @@ handle_event(_, _, State, Data) ->
call/2
when the reply cannot be defined in
the return value of a
- state function .
+ state callback .
From must be the term from argument
{call,From }
to the
- state function .
+ state callback .
A reply or multiple replies canalso be sent
using one or several
reply_action() s
from a
- state function .
+ state callback .
@@ -1562,7 +1500,7 @@ handle_event(_, _, State, Data) ->
for efficiency reasons, so this function is only called
once after server start and after code change,
but before the first
- state function
+ state callback
in the current code version is called.
More occasions may be added in future versions
of gen_statem .
@@ -1707,7 +1645,7 @@ handle_event(_, _, State, Data) ->
The Actions
are executed when entering the first
state just as for a
- state function .
+ state callback .
If the initialization fails,
@@ -1829,13 +1767,13 @@ handle_event(_, _, State, Data) ->
Module:StateName(enter, OldState, Data) ->
- StateFunctionEnterResult
+ StateEnterResult(StateName)
Module:StateName(EventType, EventContent, Data) ->
StateFunctionResult
Module:handle_event(enter, OldState, State, Data) ->
- HandleEventResult
+ StateEnterResult
Module:handle_event(EventType, EventContent, State, Data) ->
HandleEventResult
@@ -1856,20 +1794,20 @@ handle_event(_, _, State, Data) ->
data()
- StateFunctionResult =
- state_function_result()
+ StateEnterResult(StateName) =
+ state_enter_result(StateName)
- StateFunctionEnterResult =
- state_function_enter_result()
+ StateFunctionResult =
+ event_handler_result (state_name() )
- HandleEventResult =
- handle_event_result()
+ StateEnterResult =
+ state_enter_result (state() )
- HandleEventEnterResult =
- handle_event_enter_result()
+ HandleEventResult =
+ event_handler_result (state() )
@@ -1888,7 +1826,7 @@ handle_event(_, _, State, Data) ->
{call,From} ,
the caller waits for a reply. The reply can be sent
from this or from any other
- state function
+ state callback
by returning with {reply,From,Reply} in
Actions , in
Replies ,
--
cgit v1.2.3