StatesLanguage v0.2.8 StatesLanguage behaviour View Source
A macro to parse StatesLanguage JSON and create :gen_statem modules
Link to this section Summary
Types
All callbacks are expected to return a tuple containing an updated (if necessary) StatesLanguage.t/0
,
and a list of actions to perform after the callback has exectuted.
A default callback that doesn't need to do anything would just return {:ok, data, []}
Passed to all processes as the data for the :gen_statem.data.
Functions
Validates our graph data against the included JSON Schema. This is run automatically at compilation time.
Callbacks
Called when a call event has been received. It is up to your implentation to return {:reply, from, result} to send the result back to the caller.
Called when a cast event has been received.
Called when we enter a new state, but before any additional actions have occurred.
Called when a Event Timeout is triggered.
Called when a Generic Timeout is triggered.
Called when something has sent an event to our process.
Called when a Choice or Task state is transitioned to.
Called when a State Timeout is triggered.
Called when a process is ending. This can be because it was killed or a state indicated it's the end of the state machine. Used for cleanup.
Called when a transition event has been received, but before we transition to the next state.
Link to this section Types
callback_result()
View Sourcecallback_result() :: {:ok, t(), [:gen_statem.action()] | :gen_statem.action() | []}
All callbacks are expected to return a tuple containing an updated (if necessary) StatesLanguage.t/0
,
and a list of actions to perform after the callback has exectuted.
A default callback that doesn't need to do anything would just return {:ok, data, []}
Passed to all processes as the data for the :gen_statem.data.
When using the "Parallel" or "Map" types, the children processes must send/2
a message to the parent process of this type. The child_process
pid is the pid/0
of the child spawned by the parent state machine, generally the same as calling self/0
in the child process itself.
Link to this section Functions
validate(data)
View Sourcevalidate(map()) :: {:ok, map()} | {:error, Xema.Validator.result()}
Validates our graph data against the included JSON Schema. This is run automatically at compilation time.
Link to this section Callbacks
handle_call(event, from, state, data)
View Source (optional)handle_call( event :: term(), from :: GenServer.from(), state :: String.t(), data :: t() ) :: callback_result()
Called when a call event has been received. It is up to your implentation to return {:reply, from, result} to send the result back to the caller.
Arguments
- event: the payload sent with the call
- from: used to reply to the caller
- state: the current state
- data: the full data of the
:gen_statem
process
handle_cast(event, state, data)
View Source (optional)handle_cast(event :: term(), state :: String.t(), data :: t()) :: callback_result()
Called when a cast event has been received.
Arguments
- event: the payload sent with the cast
- state: the current state
- data: the full data of the
:gen_statem
process
handle_enter(old_state, state, data)
View Source (optional)handle_enter(old_state :: String.t(), state :: String.t(), data :: t()) :: callback_result()
Called when we enter a new state, but before any additional actions have occurred.
Arguments
- old_state: The previous state we were in
- state: the current state
- data: the full data of the
:gen_statem
process
handle_event_timeout(event, state, data)
View Source (optional)handle_event_timeout(event :: term(), state :: String.t(), data :: t()) :: callback_result()
Called when a Event Timeout is triggered.
Arguments
- event: The event set for the timeout
- state: the current state
- data: the full data of the
:gen_statem
process
handle_generic_timeout(event, state, data)
View Source (optional)handle_generic_timeout(event :: term(), state :: String.t(), data :: t()) :: callback_result()
Called when a Generic Timeout is triggered.
Arguments
- event: The event set for the timeout
- state: the current state
- data: the full data of the
:gen_statem
process
handle_info(event, state, data)
View Source (optional)handle_info(event :: term(), state :: String.t(), data :: t()) :: callback_result()
Called when something has sent an event to our process.
Arguments
- event: the event that was sent to us
- state: the current state
- data: the full data of the
:gen_statem
process
handle_resource(resource, params, state, data)
View Source (optional)handle_resource( resource :: String.t(), params :: term(), state :: String.t(), data :: t() ) :: callback_result()
Called when a Choice or Task state is transitioned to.
Arguments
- resource: The value of the
Resource
field for this state - params: the data after applying any JSONPath selectors to our data attribute
- state: the current state
- data: the full data of the
:gen_statem
process
handle_state_timeout(event, state, data)
View Source (optional)handle_state_timeout(event :: term(), state :: String.t(), data :: t()) :: callback_result()
Called when a State Timeout is triggered.
Arguments
- event: The event set for the timeout
- state: the current state
- data: the full data of the
:gen_statem
process
Called when a process is ending. This can be because it was killed or a state indicated it's the end of the state machine. Used for cleanup.
Arguments
- reason: the reason we are ending eg;
:normal
,:kill
, etc. - state: the current state
- data: the full data of the
:gen_statem
process
handle_transition(event, state, data)
View Source (optional)handle_transition(event :: term(), state :: String.t(), data :: t()) :: callback_result()
Called when a transition event has been received, but before we transition to the next state.
Arguments
- event: The transition event received
- state: the current state
- data: the full data of the
:gen_statem
process