View Source cure_fsm_cure_api (cure v0.7.0)

Cure FSM API Wrapper

This module provides the Cure-level FSM API that matches the design in lib/std/fsm.cure. It wraps the underlying cure_fsm_runtime gen_server to provide:

  • start_fsm/1: Start an FSM instance from a module
  • fsm_cast/2: Send events asynchronously
  • fsm_advertise/2: Register a name for an FSM
  • fsm_state/1: Query current state and payload

The FSM definitions in Cure modules are compiled to:

  1. A record type for the payload
  2. A list of transitions with handler functions
  3. An initial state and initial payload

This module bridges the gap between Cure's high-level FSM syntax and the Erlang gen_server runtime.

Summary

Functions

child_spec(Id, Module)

-spec child_spec(Id :: term(), Module :: atom()) -> map().

fsm_advertise(Pid, Name)

-spec fsm_advertise(Pid :: pid(), Name :: atom()) -> ok | {error, term()}.

fsm_call(Target, Request)

-spec fsm_call(Target :: pid() | atom(), Request :: term()) -> term().

fsm_call(Target, Request, Timeout)

-spec fsm_call(Target :: pid() | atom(), Request :: term(), Timeout :: timeout()) -> term().

fsm_cast(Target, Event)

-spec fsm_cast(Target :: pid() | atom(), Event :: {atom(), list()}) -> ok.

fsm_cast(Target, Event, Data)

-spec fsm_cast(Target :: pid() | atom(), Event :: atom(), Data :: term()) -> ok.

fsm_history(Target)

-spec fsm_history(Target :: pid() | atom()) -> {ok, [term()]} | {error, term()}.

fsm_info(Target)

-spec fsm_info(Target :: pid() | atom()) -> {ok, map()} | {error, term()}.

fsm_send_batch(Target, Events)

-spec fsm_send_batch(Target :: pid() | atom(), Events :: [term()]) -> ok.

fsm_state(Target)

-spec fsm_state(Target :: pid() | atom()) -> {ok, {atom(), term()}} | {error, term()}.

fsm_whereis(Name)

-spec fsm_whereis(Name :: atom()) -> pid() | undefined.

start_fsm(Module)

-spec start_fsm(Module :: atom()) -> {ok, pid()} | {error, term()}.

start_fsm(Module, InitData)

-spec start_fsm(Module :: atom(), InitData :: term()) -> {ok, pid()} | {error, term()}.

start_fsm_link(Module)

-spec start_fsm_link(Module :: atom()) -> {ok, pid()} | {error, term()}.

start_fsm_link(Module, InitData)

-spec start_fsm_link(Module :: atom(), InitData :: term()) -> {ok, pid()} | {error, term()}.

start_fsm_monitor(Module)

-spec start_fsm_monitor(Module :: atom()) -> {ok, {pid(), reference()}} | {error, term()}.

start_fsm_monitor(Module, InitData)

-spec start_fsm_monitor(Module :: atom(), InitData :: term()) ->
                           {ok, {pid(), reference()}} | {error, term()}.

start_supervised(Supervisor, ChildSpec)

-spec start_supervised(Supervisor :: pid() | atom(), ChildSpec :: map()) ->
                          {ok, pid()} | {error, term()}.

stop_fsm(Target)

-spec stop_fsm(Target :: pid() | atom()) -> ok | {error, term()}.