|
42 | 42 | %%----------------------------------------------------------------------------- |
43 | 43 | -module(gen_statem). |
44 | 44 |
|
45 | | --export([start/3, start/4, stop/1, stop/3, call/2, call/3, cast/2, reply/2]). |
| 45 | +-export([ |
| 46 | + start/3, start/4, start_link/3, start_link/4, stop/1, stop/3, call/2, call/3, cast/2, reply/2 |
| 47 | +]). |
46 | 48 | -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2]). |
47 | 49 |
|
48 | 50 | -record(state, { |
@@ -98,6 +100,53 @@ start({local, Name} = ServerName, Module, Args, Options) when is_atom(Name) -> |
98 | 100 | start(Module, Args, Options) -> |
99 | 101 | gen_server:start(?MODULE, {Module, Args}, Options). |
100 | 102 |
|
| 103 | +%%----------------------------------------------------------------------------- |
| 104 | +%% @param ServerName the name with which to register the gen_statem |
| 105 | +%% @param Module the module in which the gen_statem callbacks are defined |
| 106 | +%% @param Args the arguments to pass to the module's init callback |
| 107 | +%% @param Options the options used to create the gen_statem |
| 108 | +%% @returns the gen_statem pid, if successful; {error, Reason}, otherwise. |
| 109 | +%% @doc Start a named gen_statem. |
| 110 | +%% |
| 111 | +%% This function will start a gen_statem instance and register the |
| 112 | +%% newly created process with the process registry. Subsequent calls |
| 113 | +%% may use the gen_statem name, in lieu of the process id. |
| 114 | +%% |
| 115 | +%% This version of the start function will link the started gen_statem |
| 116 | +%% process to the calling process. |
| 117 | +%% |
| 118 | +%% <em><b>Note.</b> The Options argument is currently ignored.</em> |
| 119 | +%% @end |
| 120 | +%%----------------------------------------------------------------------------- |
| 121 | +-spec start_link( |
| 122 | + ServerName :: {local, Name :: atom()}, |
| 123 | + Module :: module(), |
| 124 | + Args :: term(), |
| 125 | + Options :: options() |
| 126 | +) -> {ok, pid()} | {error, Reason :: term()}. |
| 127 | +start_link({local, Name} = ServerName, Module, Args, Options) when is_atom(Name) -> |
| 128 | + gen_server:start_link(ServerName, ?MODULE, {Module, Args}, Options). |
| 129 | + |
| 130 | +%%----------------------------------------------------------------------------- |
| 131 | +%% @param Module the module in which the gen_statem callbacks are defined |
| 132 | +%% @param Args the arguments to pass to the module's init callback |
| 133 | +%% @param Options the options used to create the gen_statem |
| 134 | +%% @returns the gen_statem pid, if successful; {error, Reason}, otherwise. |
| 135 | +%% @doc Start an un-named gen_statem. |
| 136 | +%% |
| 137 | +%% This function will start a gen_statem instance. |
| 138 | +%% |
| 139 | +%% This version of the start function will link the started gen_statem |
| 140 | +%% process to the calling process. |
| 141 | +%% |
| 142 | +%% <em><b>Note.</b> The Options argument is currently ignored.</em> |
| 143 | +%% @end |
| 144 | +%%----------------------------------------------------------------------------- |
| 145 | +-spec start_link(Module :: module(), Args :: term(), Options :: options()) -> |
| 146 | + {ok, pid()} | {error, Reason :: term()}. |
| 147 | +start_link(Module, Args, Options) -> |
| 148 | + gen_server:start_link(?MODULE, {Module, Args}, Options). |
| 149 | + |
101 | 150 | %%----------------------------------------------------------------------------- |
102 | 151 | %% @equiv stop(ServerRef, normal, infinity) |
103 | 152 | %% @doc Stop a previously started gen_statem. |
|
0 commit comments