View Source Protean.Interpreter (Protean v0.0.1)
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()
@opaque invoked_service()
@type option() :: {:machine, Protean.Machine.t()} | {:handler, module()} | {:parent, GenServer.server()} | {:supervisor, Supervisor.supervisor()}
@type options() :: [option()]
@type t() :: %Protean.Interpreter{ handler: module(), internal_queue: :queue.queue(), invoked: invoked(), machine: Protean.Machine.t(), parent: pid(), running: boolean(), state: Protean.State.t(), subscribed: [{pid(), reference()}], supervisor: Supervisor.supervisor() }
Link to this section Functions
@spec handle_event(t(), Protean.event()) :: {{:ok, term()}, t()} | {nil, t()}
Handle an event, executing any transitions, actions, and side-effects associated with the current machine state.
Returns a possible answer and the interpreter state:
{{:ok, answer}, interpreter}
- if any actions resulting from handling the event set an answer on the machine state;{nil, interpreter}
- if no actions ran or none that ran set an answer.
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.
Calling start/1
on an already-running interpreter is a no-op.
@spec state(t()) :: Protean.State.t()
Return the current machine state.
Stop an interpreter, preventing further event processing and terminating any invoked processes.
@spec with_context(t(), Protean.State.context()) :: t()
Sets the context of the current state.