pool_spec

This commit is contained in:
Feng 2016-01-02 15:38:23 +08:00
parent deeaa491ca
commit f7946cc711
2 changed files with 6 additions and 2 deletions

View File

@ -26,7 +26,7 @@
-module(ecpool). -module(ecpool).
-export([start_pool/3, start_sup_pool/3, stop_sup_pool/1, -export([pool_spec/4, start_pool/3, start_sup_pool/3, stop_sup_pool/1,
with_client/2, with_client/3, name/1, workers/1]). with_client/2, with_client/3, name/1, workers/1]).
-type pool_type() :: random | hash | round_robin. -type pool_type() :: random | hash | round_robin.
@ -36,6 +36,10 @@
| {auto_reconnect, false | pos_integer()} | {auto_reconnect, false | pos_integer()}
| tuple(). | tuple().
pool_spec(ChildId, Pool, Mod, Opts) ->
{ChildId, {?MODULE, start_pool, [Pool, Mod, Opts]},
permanent, 5000, supervisor, [ecpool_pool_sup]}.
%% @doc Start the pool %% @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) -> start_pool(Pool, Mod, Opts) when is_atom(Pool) ->

View File

@ -36,7 +36,7 @@ start_link(Pool, Mod, Opts) when is_atom(Pool) ->
init([Pool, Mod, Opts]) -> init([Pool, Mod, Opts]) ->
WorkerSpec = fun(Id) -> WorkerSpec = fun(Id) ->
{{worker, Id}, {ecpool_worker, start_link, [Pool, Id, Mod, Opts]}, {{worker, Id}, {ecpool_worker, start_link, [Pool, Id, Mod, Opts]},
transient, 5000, worker, [ecpool_worker]} transient, 5000, worker, [ecpool_worker, Mod]}
end, end,
Workers = [WorkerSpec(I) || I <- lists:seq(1, pool_size(Opts))], Workers = [WorkerSpec(I) || I <- lists:seq(1, pool_size(Opts))],
{ok, { {one_for_one, 10, 60}, Workers} }. {ok, { {one_for_one, 10, 60}, Workers} }.