StatesLanguage behaviour (StatesLanguage v0.3.0) 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.
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.
Functions
Validates our graph data against the included JSON Schema. This is run automatically at compilation time.
Link to this section Types
Specs
callback_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, []}
Specs
Passed to all processes as the data for the :gen_statem.data.
Specs
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 Callbacks
Specs
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
Specs
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
Specs
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
Specs
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
Specs
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
Specs
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
Specs
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
Specs
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
Specs
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
Specs
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
Link to this section Functions
Specs
validate(map()) :: {:ok, map()} | {:error, Xema.Validator.result()}
Validates our graph data against the included JSON Schema. This is run automatically at compilation time.