StateMachine.Event (state_machine v0.1.6)

Event is a container for transitions. It is identified by name (atom) and can contain arbitrary number of transtitions.

One important thing is that it's disallowed to have more than one unguarded transition from the state, since this would introduce a "non-determinism" (or rather just discard the latter transition). We loosely allow guarded transitions from the same state, but it doesn't guarantee anything: if guards always return true, we're back to where we were before.

Link to this section Summary

Functions

Private function for running Event callbacks.

Checks if the event is allowed in the current context. First it makes sure that all guards of the event return true, then it scans transitions for the matching one. Match is determined by the source state and passing of all guards as well.

This is an entry point for transition. By running this function with populated context, event and optional payload, you tell state machine to try to move to the next state. It returns an updated context.

Link to this section Types

Link to this type

callback_pos()

Specs

callback_pos() :: :before | :after

Specs

t(model) :: %StateMachine.Event{
  after: [StateMachine.Callback.t(model)],
  before: [StateMachine.Callback.t(model)],
  guards: [StateMachine.Guard.t(model)],
  name: atom(),
  transitions: [StateMachine.Transition.t(model)]
}

Link to this section Functions

Link to this function

callback(ctx, pos)

Specs

Private function for running Event callbacks.

Link to this function

is_allowed?(ctx, event)

Specs

is_allowed?(StateMachine.Context.t(model), t(model) | atom()) :: boolean()

Checks if the event is allowed in the current context. First it makes sure that all guards of the event return true, then it scans transitions for the matching one. Match is determined by the source state and passing of all guards as well.

Link to this function

trigger(ctx, event, payload \\ nil)

Specs

trigger(StateMachine.Context.t(model), atom(), any()) ::
  StateMachine.Context.t(model)

This is an entry point for transition. By running this function with populated context, event and optional payload, you tell state machine to try to move to the next state. It returns an updated context.