View Source partisan_gen_statem behaviour (partisan v5.0.0-beta.15)

This module is an adaptation of Erlang's gen_statem module.

It replaces all instances of erlang:send/2 and erlang:monitor/2 with their Partisan counterparts.

It maintains the gen_statem API with the following exceptions:

  • call/3` - overrides the 3rd to accept not only a timeout value but also a list of options containing any of the following: `{timeout, timeout()} | {channel, partisan:channel()}.
  • cast/3` - identical to `cast/2 with the 3th argument is a list of options containing any of the following: {channel, partisan:channel()}.
  • send_request/4` - identical to `send_request/3 with the 4th argument is a list of options containing any of the following: {channel, partisan:channel()}.

NOTICE

At the moment this only works for partisan_pluggable_peer_service_manager backend.

Link to this section Summary

Callbacks

State callback for all states when callback_mode() =:= handle_event_function.

Link to this section Types

-type action() ::
    postpone |
    {postpone, Postpone :: postpone()} |
    {next_event, EventType :: event_type(), EventContent :: term()} |
    {change_callback_module, NewModule :: module()} |
    {push_callback_module, NewModule :: module()} |
    pop_callback_module |
    enter_action().
-type callback_mode() :: state_functions | handle_event_function.
Link to this type

callback_mode_result/0

View Source
-type callback_mode_result() :: callback_mode() | [callback_mode() | state_enter()].
-type data() :: term().
-type enter_action() ::
    hibernate | {hibernate, Hibernate :: hibernate()} | timeout_action() | reply_action().
-type enter_loop_opt() ::
    {hibernate_after, HibernateAfterTimeout :: timeout()} | {debug, Dbgs :: [sys:debug_option()]}.
Link to this type

event_handler_result/1

View Source
-type event_handler_result(StateType) :: event_handler_result(StateType, term()).
Link to this type

event_handler_result/2

View Source
-type event_handler_result(StateType, DataType) ::
    {next_state, NextState :: StateType, NewData :: DataType} |
    {next_state, NextState :: StateType, NewData :: DataType, Actions :: [action()] | action()} |
    state_callback_result(action()).
-type event_timeout() :: Time :: timeout() | integer().
-type event_type() :: external_event_type() | timeout_event_type() | internal.
-type external_event_type() :: {call, From :: from()} | cast | info.
-type from() :: {To :: pid(), Tag :: term()}.
Reply-to specifier for call
-type generic_timeout() :: Time :: timeout() | integer().
-type handle_event_result() :: event_handler_result(state()).
-type hibernate() :: boolean().
-type init_result(StateType) :: init_result(StateType, term()).
-type init_result(StateType, DataType) ::
    {ok, State :: StateType, Data :: DataType} |
    {ok, State :: StateType, Data :: DataType, Actions :: [action()] | action()} |
    ignore |
    {stop, Reason :: term()}.
-type postpone() :: boolean().
-type reply_action() :: {reply, From :: from(), Reply :: term()}.
-type request_id() :: term().
-type server_name() ::
    {global, GlobalName :: term()} | {via, RegMod :: module(), Name :: term()} | {local, atom()}.
-type server_ref() ::
    pid() |
    (LocalName :: atom()) |
    {Name :: atom(), Node :: atom()} |
    {global, GlobalName :: term()} |
    {via, RegMod :: module(), ViaName :: term()}.
-type start_mon_ret() :: {ok, {pid(), reference()}} | ignore | {error, term()}.
-type start_opt() ::
    {timeout, Time :: timeout()} | {spawn_opt, [proc_lib:start_spawn_option()]} | enter_loop_opt().
-type start_ret() :: {ok, pid()} | ignore | {error, term()}.
-type state() :: state_name() | term().
For handle_event/4 callback function
Link to this type

state_callback_result/1

View Source
-type state_callback_result(ActionType) :: state_callback_result(ActionType, term()).
Link to this type

state_callback_result/2

View Source
-type state_callback_result(ActionType, DataType) ::
    {keep_state, NewData :: DataType} |
    {keep_state, NewData :: DataType, Actions :: [ActionType] | ActionType} |
    keep_state_and_data |
    {keep_state_and_data, Actions :: [ActionType] | ActionType} |
    {repeat_state, NewData :: DataType} |
    {repeat_state, NewData :: DataType, Actions :: [ActionType] | ActionType} |
    repeat_state_and_data |
    {repeat_state_and_data, Actions :: [ActionType] | ActionType} |
    stop |
    {stop, Reason :: term()} |
    {stop, Reason :: term(), NewData :: DataType} |
    {stop_and_reply, Reason :: term(), Replies :: [reply_action()] | reply_action()} |
    {stop_and_reply,
     Reason :: term(),
     Replies :: [reply_action()] | reply_action(),
     NewData :: DataType}.
-type state_enter() :: state_enter.
-type state_enter_result(State) :: state_enter_result(State, term()).
-type state_enter_result(State, DataType) ::
    {next_state, State, NewData :: DataType} |
    {next_state, State, NewData :: DataType, Actions :: [enter_action()] | enter_action()} |
    state_callback_result(enter_action()).
Link to this type

state_function_result/0

View Source
-type state_function_result() :: event_handler_result(state_name()).
-type state_name() :: atom().
-type state_timeout() :: Time :: timeout() | integer().
-type timeout_action() ::
    (Time :: event_timeout()) |
    {timeout, Time :: event_timeout(), EventContent :: term()} |
    {timeout,
     Time :: event_timeout(),
     EventContent :: term(),
     Options :: timeout_option() | [timeout_option()]} |
    {{timeout, Name :: term()}, Time :: generic_timeout(), EventContent :: term()} |
    {{timeout, Name :: term()},
     Time :: generic_timeout(),
     EventContent :: term(),
     Options :: timeout_option() | [timeout_option()]} |
    {state_timeout, Time :: state_timeout(), EventContent :: term()} |
    {state_timeout,
     Time :: state_timeout(),
     EventContent :: term(),
     Options :: timeout_option() | [timeout_option()]} |
    timeout_cancel_action() |
    timeout_update_action().
Link to this type

timeout_cancel_action/0

View Source
-type timeout_cancel_action() ::
    {timeout, cancel} | {{timeout, Name :: term()}, cancel} | {state_timeout, cancel}.
-type timeout_event_type() :: timeout | {timeout, Name :: term()} | state_timeout.
-type timeout_option() :: {abs, Abs :: boolean()}.
Link to this type

timeout_update_action/0

View Source
-type timeout_update_action() ::
    {timeout, update, EventContent :: term()} |
    {{timeout, Name :: term()}, update, EventContent :: term()} |
    {state_timeout, update, EventContent :: term()}.
-type transition_option() ::
    postpone() | hibernate() | event_timeout() | generic_timeout() | state_timeout().

Link to this section Callbacks

-callback callback_mode() -> callback_mode_result().
Link to this callback

code_change/4

View Source (optional)
-callback code_change(OldVsn :: term() | {down, term()},
            OldState :: state(),
            OldData :: data(),
            Extra :: term()) ->
               {ok, NewState :: state(), NewData :: data()} | (Reason :: term()).
Link to this callback

format_status/2

View Source (optional)
-callback format_status(StatusOption, [[{Key :: term(), Value :: term()}] | state() | data()]) ->
                 Status :: term()
                 when StatusOption :: normal | terminate.
Link to this callback

handle_event/4

View Source (optional)
-callback handle_event(enter, OldState :: state(), State, Data :: data()) -> state_enter_result(State);
            (event_type(), EventContent :: term(), State :: state(), Data :: data()) ->
                event_handler_result(state()).
-callback init(Args :: term()) -> init_result(state()).
-callback state_name(enter, OldStateName :: state_name(), Data :: data()) -> state_enter_result(state_name);
          (event_type(), EventContent :: term(), Data :: data()) ->
              event_handler_result(state_name()).
State callback for all states when callback_mode() =:= handle_event_function.
-callback terminate(Reason :: normal | shutdown | {shutdown, term()} | term(),
          State :: state(),
          Data :: data()) ->
             any().

Link to this section Functions

Link to this function

call(ServerRef, Request)

View Source
-spec call(ServerRef :: server_ref(), Request :: term()) -> Reply :: term().
Link to this function

call(ServerRef, Request, Timeout)

View Source
-spec call(ServerRef :: server_ref(),
     Request :: term(),
     Timeout ::
         timeout() |
         {clean_timeout, T :: timeout()} |
         {dirty_timeout, T :: timeout()} |
         [{timeout, timeout()} |
          {clean_timeout, T :: timeout()} |
          {dirty_timeout, T :: timeout()} |
          {any(), term()}]) ->
        Reply :: term().
-spec cast(ServerRef :: server_ref(), Msg :: term()) -> ok.
Link to this function

cast(ServerRef, Request, Opts)

View Source
Link to this function

check_response(Msg, RequestId)

View Source
-spec check_response(Msg :: term(), RequestId :: request_id()) ->
                  {reply, Reply :: term()} | no_reply | {error, {term(), server_ref()}}.
Link to this function

enter_loop(Module, Opts, State, Data)

View Source
-spec enter_loop(Module :: module(), Opts :: [enter_loop_opt()], State :: state(), Data :: data()) ->
              no_return().
Link to this function

enter_loop(Module, Opts, State, Data, Server_or_Actions)

View Source
-spec enter_loop(Module :: module(),
           Opts :: [enter_loop_opt()],
           State :: state(),
           Data :: data(),
           Server_or_Actions :: server_name() | pid() | [action()]) ->
              no_return().
Link to this function

enter_loop(Module, Opts, State, Data, Server, Actions)

View Source
-spec enter_loop(Module :: module(),
           Opts :: [enter_loop_opt()],
           State :: state(),
           Data :: data(),
           Server :: server_name() | pid(),
           Actions :: [action()] | action()) ->
              no_return().
Link to this function

format_log(Report, FormatOpts0)

View Source
Link to this function

init_it(Starter, Parent, ServerRef, Module, Args, Opts)

View Source
Link to this function

receive_response(RequestId)

View Source
-spec receive_response(RequestId :: request_id()) ->
                    {reply, Reply :: term()} | {error, {term(), server_ref()}}.
Link to this function

receive_response(RequestId, Timeout)

View Source
-spec receive_response(RequestId :: request_id(), timeout()) ->
                    {reply, Reply :: term()} | timeout | {error, {term(), server_ref()}}.
-spec reply([reply_action()] | reply_action()) -> ok.
-spec reply(From :: from(), Reply :: term()) -> ok.
Link to this function

send_request(ServerRef, Request)

View Source
-spec send_request(ServerRef :: server_ref(), Request :: term()) -> RequestId :: request_id().
Link to this function

send_request(Name, Request, Opts)

View Source
-spec send_request(Name :: server_ref(), Request :: term(), Opts :: list()) -> RequestId :: request_id().
Link to this function

start(Module, Args, Opts)

View Source
-spec start(Module :: module(), Args :: term(), Opts :: [start_opt()]) -> start_ret().
Link to this function

start(ServerName, Module, Args, Opts)

View Source
-spec start(ServerName :: server_name(), Module :: module(), Args :: term(), Opts :: [start_opt()]) ->
         start_ret().
Link to this function

start_link(Module, Args, Opts)

View Source
-spec start_link(Module :: module(), Args :: term(), Opts :: [start_opt()]) -> start_ret().
Link to this function

start_link(ServerName, Module, Args, Opts)

View Source
-spec start_link(ServerName :: server_name(), Module :: module(), Args :: term(), Opts :: [start_opt()]) ->
              start_ret().
Link to this function

start_monitor(Module, Args, Opts)

View Source
-spec start_monitor(Module :: module(), Args :: term(), Opts :: [start_opt()]) -> start_mon_ret().
Link to this function

start_monitor(ServerName, Module, Args, Opts)

View Source
-spec start_monitor(ServerName :: server_name(),
              Module :: module(),
              Args :: term(),
              Opts :: [start_opt()]) ->
                 start_mon_ret().
-spec stop(ServerRef :: server_ref()) -> ok.
Link to this function

stop(ServerRef, Reason, Timeout)

View Source
-spec stop(ServerRef :: server_ref(), Reason :: term(), Timeout :: timeout()) -> ok.
Link to this function

system_code_change(_, Mod, OldVsn, Extra)

View Source
Link to this function

system_continue(Parent, Debug, _)

View Source
Link to this function

system_replace_state(StateFun, _)

View Source
Link to this function

system_terminate(Reason, Parent, Debug, _)

View Source
Link to this function

wait_response(RequestId)

View Source
-spec wait_response(RequestId :: request_id()) ->
                 {reply, Reply :: term()} | {error, {term(), server_ref()}}.
Link to this function

wait_response(RequestId, Timeout)

View Source
-spec wait_response(RequestId :: request_id(), timeout()) ->
                 {reply, Reply :: term()} | timeout | {error, {term(), server_ref()}}.
Link to this function

wakeup_from_hibernate(P, Debug, S)

View Source