Added specs for gm callbacks.

This commit is contained in:
Francesco Mazzoli 2012-03-05 16:18:50 +00:00
parent 42b19d8c4e
commit a27ec7d826
2 changed files with 57 additions and 48 deletions

View File

@ -252,7 +252,7 @@
{stop, Reason :: term(), NewState :: term()}.
-callback terminate(Reason :: (normal | shutdown | {shutdown, term()} | term()),
State :: term()) ->
(ok | term()).
ok | term().
-callback code_change(OldVsn :: (term() | {down, term()}), State :: term(),
Extra :: term()) ->
{ok, NewState :: term()} | {error, Reason :: term()}.

View File

@ -57,8 +57,8 @@
%% you wish to be passed into the callback module's functions. The
%% joined/2 function will be called when we have joined the group,
%% with the arguments passed to start_link and a list of the current
%% members of the group. See the comments in behaviour_info/1 below
%% for further details of the callback functions.
%% members of the group. See the callbacks specs and the comments
%% below for further details of the callback functions.
%%
%% leave/1
%% Provide the Pid. Removes the Pid from the group. The callback
@ -378,7 +378,9 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
code_change/3, prioritise_info/2]).
-ifndef(use_specs).
-export([behaviour_info/1]).
-endif.
-export([table_definitions/0]).
@ -431,10 +433,6 @@
-spec(confirmed_broadcast/2 :: (pid(), any()) -> 'ok').
-spec(group_members/1 :: (pid()) -> [pid()]).
-endif.
behaviour_info(callbacks) ->
[
%% The joined, members_changed and handle_msg callbacks can all
%% return any of the following terms:
%%
@ -451,7 +449,8 @@ behaviour_info(callbacks) ->
%% Called when we've successfully joined the group. Supplied with
%% Args provided in start_link, plus current group members.
{joined, 2},
-callback joined(Args :: term(), Members :: [pid()]) ->
ok | {stop, Reason :: term()} | {become, Module :: atom(), Args :: any()}.
%% Supplied with Args provided in start_link, the list of new
%% members and the list of members previously known to us that
@ -463,7 +462,9 @@ behaviour_info(callbacks) ->
%% any messages from it; and (2) we will not see members die that
%% we have not seen born (or supplied in the members to
%% joined/2).
{members_changed, 3},
-callback members_changed(Args :: term(), Births :: [pid()],
Deaths :: [pid()]) ->
ok | {stop, Reason :: term()} | {become, Module :: atom(), Args :: any()}.
%% Supplied with Args provided in start_link, the sender, and the
%% message. This does get called for messages injected by this
@ -471,16 +472,24 @@ behaviour_info(callbacks) ->
%% significance of this invocation: it does not indicate that the
%% message has made it to any other members, let alone all other
%% members.
{handle_msg, 3},
-callback handle_msg(Args :: term(), From :: pid(), Message :: term()) ->
ok | {stop, Reason :: term()} | {become, Module :: atom(), Args :: any()}.
%% Called on gm member termination as per rules in gen_server,
%% with the Args provided in start_link plus the termination
%% Reason.
{terminate, 2}
];
-callback terminate(Args :: term(), Reason :: term()) ->
ok | term().
-else.
behaviour_info(callbacks) ->
[{joined, 2}, {members_changed, 3}, {handle_msg, 3}, {terminate, 2}];
behaviour_info(_Other) ->
undefined.
-endif.
create_tables() ->
create_tables([?TABLE]).