Update comment and format code
This commit is contained in:
parent
93c263741c
commit
31e26ec5df
|
@ -4,8 +4,7 @@
|
|||
{require_min_otp_vsn, "R20"}.
|
||||
|
||||
%warnings_as_errors, warn_untyped_record,
|
||||
{erl_opts, [
|
||||
warn_export_all,
|
||||
{erl_opts, [warn_export_all,
|
||||
warn_unused_import,
|
||||
{i, "include"},
|
||||
{src_dirs, ["src"]}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -11,6 +12,7 @@
|
|||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-module(ecpool).
|
||||
|
||||
|
@ -19,6 +21,13 @@
|
|||
set_reconnect_callback/2,
|
||||
name/1, workers/1]).
|
||||
|
||||
-export_type([pool_name/0,
|
||||
pool_type/0,
|
||||
option/0
|
||||
]).
|
||||
|
||||
-type pool_name() :: term().
|
||||
|
||||
-type pool_type() :: random | hash | round_robin.
|
||||
|
||||
-type reconn_callback() :: {fun((pid()) -> term())}.
|
||||
|
@ -29,11 +38,6 @@
|
|||
| {on_reconnect, reconn_callback()}
|
||||
| tuple().
|
||||
|
||||
-export_type([pool_name/0,
|
||||
pool_type/0,
|
||||
option/0
|
||||
]).
|
||||
|
||||
pool_spec(ChildId, Pool, Mod, Opts) ->
|
||||
#{id => ChildId,
|
||||
start => {?MODULE, start_pool, [Pool, Mod, Opts]},
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -11,6 +12,7 @@
|
|||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-module(ecpool_app).
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -11,6 +12,7 @@
|
|||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-module(ecpool_pool).
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -11,6 +12,7 @@
|
|||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-module(ecpool_pool_sup).
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -11,6 +12,7 @@
|
|||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-module(ecpool_sup).
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -11,6 +12,7 @@
|
|||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-module(ecpool_worker).
|
||||
|
||||
|
@ -19,7 +21,7 @@
|
|||
-export([start_link/4]).
|
||||
|
||||
%% API Function Exports
|
||||
-export([start_link/4, client/1, is_connected/1, set_reconnect_callback/2]).
|
||||
-export([client/1, is_connected/1, set_reconnect_callback/2]).
|
||||
|
||||
%% gen_server Function Exports
|
||||
-export([init/1,
|
||||
|
@ -121,8 +123,8 @@ handle_info({'EXIT', Pid, Reason}, State = #state{client = Pid, opts = Opts}) ->
|
|||
reconnect_after(Secs, State)
|
||||
end;
|
||||
|
||||
handle_info(reconnect, State = #state{opts = Opts, on_reconnect = OnReconnect}) ->
|
||||
case catch connect(State) of
|
||||
handle_info(reconnect, State = #state{pool = Pool, opts = Opts, on_reconnect = OnReconnect}) ->
|
||||
try connect(State) of
|
||||
{ok, Client} ->
|
||||
handle_reconnect(Client, OnReconnect),
|
||||
{noreply, State#state{client = Client}};
|
||||
|
@ -176,3 +178,7 @@ handle_reconnect(_, undefined) ->
|
|||
ok;
|
||||
handle_reconnect(Client, OnReconnect) ->
|
||||
OnReconnect(Client).
|
||||
|
||||
maybe_apply(undefined, _) -> ok;
|
||||
maybe_apply(Fun, Arg) -> erlang:apply(Fun, [Arg]).
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -11,6 +12,7 @@
|
|||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-module(ecpool_worker_sup).
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -11,6 +12,7 @@
|
|||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-module(ecpool_SUITE).
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2019 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -11,6 +12,7 @@
|
|||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-module(test_client).
|
||||
|
||||
|
|
Loading…
Reference in New Issue