Module gen_statem

An implementation of the Erlang/OTP gen_statem interface.

This module defines the gen_statem behaviour.
Required callback functions: init/1, callback_mode/0.

Description

This module implements a strict susbset of the Erlang/OTP gen_statem interface, supporting operations for local creation and management of gen_statem instances.

This module is designed to be API-compatible with gen_statem, with exceptions noted below.

Caveats:

  • No support for start_link

  • Support only for locally named gen_statem instances

  • Support only for state function event handlers

  • No support for keep_state or repeat_state return values from Module:StateName/3 callbacks

  • No support for postpone or hibernate state transition actions

  • No support for state enter calls

  • No support for multi_call

Data Types

options()


options() = [{atom(), term()}]

server_ref()


server_ref() = atom() | pid()

Function Index

call/2 Send a request to a gen_statem instance, and wait for a reply.
call/3 Send a request to a gen_statem instance, and wait for a reply..
cast/2 Send a request to a gen_statem instance.
reply/2 Send a reply to a calling client.
start/3 Start an un-named gen_statem.
start/4 Start a named gen_statem.
start_link/3 Start an un-named gen_statem.
start_link/4 Start a named gen_statem.
stop/1 Stop a previously started gen_statem.
stop/3 Stop a previously started gen_statem instance.

Function Details

call/2


call(ServerRef::server_ref(), Request::term()) -> Reply::term() | {error, Reason::term()}

Equivalent to call(ServerRef, Request, infinity).

Send a request to a gen_statem instance, and wait for a reply.

call/3


call(ServerRef::server_ref(), Request::term(), Timeout::timeout()) -> Reply::term() | {error, Reason::term()}

ServerRef: a reference to the gen_statem acquired via start
Request: the request to send to the gen_statem
Timeout: the amount of time in milliseconds to wait for a reply

returns: the reply sent back from the gen_statem; {error, Reason}, otherwise.

Send a request to a gen_statem instance, and wait for a reply..

This function will send the specified request to the specified gen_statem instance, and wait at least Timeout milliseconds for a reply from the gen_statem.

cast/2


cast(ServerRef::server_ref(), Request::term()) -> ok | {error, Reason::term()}

ServerRef: a reference to the gen_statem acquired via start
Request: the request to send to the gen_statem

returns: ok | {error, Reason}

Send a request to a gen_statem instance.

This function will send the specified request to the specified gen_statem instance, but will not wait for a reply.

reply/2


reply(Client::pid(), Reply::term()) -> term()

Client: the client to whom to send the reply
Reply: the reply to send to the client

returns: an arbitrary term, that should be ignored

Send a reply to a calling client.

This function will send the specified reply back to the specified gen_statem client (e.g, via call/3). The return value of this function can be safely ignored.

start/3


start(Module::module(), Args::term(), Options::options()) -> {ok, pid()} | {error, Reason::term()}

Module: the module in which the gen_statem callbacks are defined
Args: the arguments to pass to the module’s init callback
Options: the options used to create the gen_statem

returns: the gen_statem pid, if successful; {error, Reason}, otherwise.

Start an un-named gen_statem.

This function will start a gen_statem instance.

Note. The Options argument is currently ignored.

start/4


start(ServerName::{local, Name::atom()}, Module::module(), Args::term(), Options::options()) -> {ok, pid()} | {error, Reason::term()}

ServerName: the name with which to register the gen_statem
Module: the module in which the gen_statem callbacks are defined
Args: the arguments to pass to the module’s init callback
Options: the options used to create the gen_statem

returns: the gen_statem pid, if successful; {error, Reason}, otherwise.

Start a named gen_statem.

This function will start a gen_statem instance and register the newly created process with the process registry. Subsequent calls may use the gen_statem name, in lieu of the process id.

Note. The Options argument is currently ignored.

stop/1


stop(ServerRef::server_ref()) -> ok | {error, Reason::term()}

Equivalent to stop(ServerRef, normal, infinity).

Stop a previously started gen_statem.

stop/3


stop(ServerRef::server_ref(), Reason::term(), Timeout::non_neg_integer() | infinity) -> ok | {error, Reason::term()}

ServerRef: a reference to the gen_statem acquired via start

returns: ok, if the gen_statem stopped; {error, Reason}, otherwise.

Stop a previously started gen_statem instance.

This function will stop a gen_statem instance, providing the supplied Reason to the . If the gen_statem is a named gen_statem, then the gen_statem name may be used to stop the gen_statem.