Spec Syntax
This commit is contained in:
parent
f1cbfee1fc
commit
6befd736e7
|
@ -42,7 +42,7 @@ pool_spec(ChildId, Pool, Mod, Opts) ->
|
|||
permanent, 5000, supervisor, [ecpool_pool_sup]}.
|
||||
|
||||
%% @doc Start the pool
|
||||
-spec start_pool(atom(), atom(), [option()]) -> {ok, pid()} | {error, any()}.
|
||||
-spec(start_pool(atom(), atom(), [option()]) -> {ok, pid()} | {error, any()}).
|
||||
start_pool(Pool, Mod, Opts) when is_atom(Pool) ->
|
||||
ecpool_pool_sup:start_link(Pool, Mod, Opts).
|
||||
|
||||
|
@ -55,22 +55,22 @@ stop_sup_pool(Pool) when is_atom(Pool) ->
|
|||
ecpool_sup:stop_pool(Pool).
|
||||
|
||||
%% @doc Get client/connection
|
||||
-spec get_client(atom()) -> pid().
|
||||
-spec(get_client(atom()) -> pid()).
|
||||
get_client(Pool) ->
|
||||
gproc_pool:pick_worker(name(Pool)).
|
||||
|
||||
%% @doc Get client/connection with hash key.
|
||||
-spec get_client(atom(), any()) -> pid().
|
||||
-spec(get_client(atom(), any()) -> pid()).
|
||||
get_client(Pool, Key) ->
|
||||
gproc_pool:pick_worker(name(Pool), Key).
|
||||
|
||||
%% @doc Call the fun with client/connection
|
||||
-spec with_client(atom(), fun((Client :: pid()) -> any())) -> any().
|
||||
-spec(with_client(atom(), fun((Client :: pid()) -> any())) -> any()).
|
||||
with_client(Pool, Fun) when is_atom(Pool) ->
|
||||
with_worker(gproc_pool:pick_worker(name(Pool)), Fun).
|
||||
|
||||
%% @doc Call the fun with client/connection
|
||||
-spec with_client(atom(), any(), fun((Client :: pid()) -> any())) -> any().
|
||||
-spec(with_client(atom(), any(), fun((Client :: pid()) -> any())) -> any()).
|
||||
with_client(Pool, Key, Fun) when is_atom(Pool) ->
|
||||
with_worker(gproc_pool:pick_worker(name(Pool), Key), Fun).
|
||||
|
||||
|
|
|
@ -35,14 +35,14 @@
|
|||
-export([init/1]).
|
||||
|
||||
%% @doc Start supervisor.
|
||||
-spec start_link() -> {ok, pid()} | {error, any()}.
|
||||
-spec(start_link() -> {ok, pid()} | {error, any()}).
|
||||
start_link() ->
|
||||
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
||||
|
||||
start_pool(Pool, Mod, Opts) when is_atom(Pool) ->
|
||||
supervisor:start_child(?MODULE, pool_spec(Pool, Mod, Opts)).
|
||||
|
||||
-spec stop_pool(Pool :: atom()) -> ok | {error, any()}.
|
||||
-spec(stop_pool(Pool :: atom()) -> ok | {error, any()}).
|
||||
stop_pool(Pool) when is_atom(Pool) ->
|
||||
ChildId = child_id(Pool),
|
||||
case supervisor:terminate_child(?MODULE, ChildId) of
|
||||
|
@ -53,13 +53,13 @@ stop_pool(Pool) when is_atom(Pool) ->
|
|||
end.
|
||||
|
||||
%% @doc All Pools supervisored by ecpool_sup.
|
||||
-spec pools() -> [{atom(), pid()}].
|
||||
-spec(pools() -> [{atom(), pid()}]).
|
||||
pools() ->
|
||||
[{Pool, Pid} || {{pool_sup, Pool}, Pid, supervisor, _}
|
||||
<- supervisor:which_children(?MODULE)].
|
||||
|
||||
%% @doc Find a pool.
|
||||
-spec pool(atom()) -> undefined | pid().
|
||||
-spec(pool(atom()) -> undefined | pid()).
|
||||
pool(Pool) when is_atom(Pool) ->
|
||||
ChildId = child_id(Pool),
|
||||
case [Pid || {Id, Pid, supervisor, _} <- supervisor:which_children(?MODULE), Id =:= ChildId] of
|
||||
|
|
|
@ -61,19 +61,19 @@ behaviour_info(_Other) ->
|
|||
%%% API
|
||||
%%%=============================================================================
|
||||
|
||||
%% @doc Start the pool worker.
|
||||
-spec start_link(atom(), pos_integer(), module(), list()) ->
|
||||
{ok, pid()} | ignore | {error, any()}.
|
||||
%% @doc Start a pool worker.
|
||||
-spec(start_link(atom(), pos_integer(), module(), list()) ->
|
||||
{ok, pid()} | ignore | {error, any()}).
|
||||
start_link(Pool, Id, Mod, Opts) ->
|
||||
gen_server:start_link(?MODULE, [Pool, Id, Mod, Opts], []).
|
||||
|
||||
%% @doc Get client/connection.
|
||||
-spec client(pid()) -> undefined | pid().
|
||||
-spec(client(pid()) -> undefined | pid()).
|
||||
client(Pid) ->
|
||||
gen_server:call(Pid, client, infinity).
|
||||
|
||||
%% @doc Is client connected?
|
||||
-spec is_connected(pid()) -> boolean().
|
||||
-spec(is_connected(pid()) -> boolean()).
|
||||
is_connected(Pid) ->
|
||||
gen_server:call(Pid, is_connected).
|
||||
|
||||
|
@ -113,10 +113,10 @@ handle_info({'EXIT', Pid, Reason}, State = #state{client = Pid, opts = Opts}) ->
|
|||
end;
|
||||
|
||||
handle_info(reconnect, State = #state{opts = Opts}) ->
|
||||
case connect(State) of
|
||||
case catch connect(State) of
|
||||
{ok, Client} ->
|
||||
{noreply, State#state{client = Client}};
|
||||
{error, _Error} ->
|
||||
{Err, _Reason} when Err =:= error orelse Err =:= 'EXIT' ->
|
||||
reconnect(proplists:get_value(auto_reconnect, Opts), State)
|
||||
end;
|
||||
|
||||
|
|
Loading…
Reference in New Issue