View Source Protean.Interpreter (Protean v0.0.3)

Execution logic for a Protean machine.

Link to this section Summary

Functions

Handle an event, executing any transitions, actions, and side-effects associated with the current machine state.

Create a new Interpreter. The returned interpreter will still need to be started, which could result in additional side-effects. See start/1.

Whether the interpreter has been started and can accept events.

Entrypoint for the interpreter that must be called before the interpreter will be in a state where it can handle external events. This is necessary in order to handle any initializing actions, invokes, or automatic transitions.

Return the current machine state.

Stop an interpreter, preventing further event processing and terminating any invoked processes.

Sets the context of the current state.

Link to this section Types

@type invoked() :: %{required(invoked_id()) => invoked_service()}
@type invoked_id() :: String.t()
Link to this opaque

invoked_service()

View Source (opaque)
@opaque invoked_service()
@type t() :: %Protean.Interpreter{
  config: Protean.MachineConfig.t(),
  internal_queue: :queue.queue(),
  invoked: invoked(),
  parent: pid(),
  running: boolean(),
  state: Protean.State.t(),
  subscribers: %{required(reference()) => %{pid: pid(), to: :all | :replies}},
  supervisor: Supervisor.supervisor()
}

Link to this section Functions

Link to this function

handle_event(interpreter, event)

View Source
@spec handle_event(t(), Protean.event()) :: {t(), [term()]}

Handle an event, executing any transitions, actions, and side-effects associated with the current machine state.

Returns a tuple of the interpreter and any replies resulting from actions that were run.

@spec new([Protean.machine_option()]) :: t()

Create a new Interpreter. The returned interpreter will still need to be started, which could result in additional side-effects. See start/1.

@spec running?(t()) :: boolean()

Whether the interpreter has been started and can accept events.

@spec start(t()) :: t()

Entrypoint for the interpreter that must be called before the interpreter will be in a state where it can handle external events. This is necessary in order to handle any initializing actions, invokes, or automatic transitions.

Calling start/1 on an already-running interpreter is a no-op.

@spec state(t()) :: Protean.State.t()

Return the current machine state.

@spec stop(t()) :: t()

Stop an interpreter, preventing further event processing and terminating any invoked processes.

Link to this function

subscribe(interpreter, map)

View Source
Link to this function

unsubscribe(interpreter, ref)

View Source
Link to this function

with_context(interpreter, context)

View Source
@spec with_context(t(), Protean.State.context()) :: t()

Sets the context of the current state.