StatesLanguage behaviour (StatesLanguage v0.4.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, []}

t()

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.

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 something has sent an event to our process.

Called when a Choice or Task state is transitioned to.

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

t() :: %StatesLanguage{
  _parent: pid(),
  _parent_data: any(),
  _tasks: [],
  data: any()
}

Passed to all processes as the data for the :gen_statem.data.

  • _parent is used to reference a parent process within a Map or Parallel state type
  • _parent_data is the data from the parent
  • data is the data passed to this process on startup
  • _tasks is used to keep track of child processes for Map and Parallel state types

Specs

task_processed() :: {:task_processed, result :: any(), child_process :: pid()}

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

Link to this callback

handle_call( event, from, state, data )

View Source (optional)

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
Link to this callback

handle_cast(event, state, data)

View Source (optional)

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
Link to this callback

handle_enter(old_state, state, data)

View Source (optional)

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
Link to this callback

handle_event_timeout(event, state, data)

View Source (optional)

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
Link to this callback

handle_generic_timeout(event, state, data)

View Source (optional)

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
Link to this callback

handle_info(event, state, data)

View Source (optional)

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
Link to this callback

handle_resource( resource, params, state, data )

View Source (optional)

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
Link to this callback

handle_state_timeout(event, state, data)

View Source (optional)

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
Link to this callback

handle_termination(reason, state, data)

View Source (optional)

Specs

handle_termination(reason :: term(), state :: String.t(), data :: t()) :: :ok

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
Link to this callback

handle_transition(event, state, data)

View Source (optional)

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.