Add add_reconnect_callback/2
This commit is contained in:
parent
0b597baa9e
commit
b5ba453872
|
@ -28,7 +28,7 @@
|
||||||
, workers/1
|
, workers/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-export([set_reconnect_callback/2]).
|
-export([set_reconnect_callback/2, add_reconnect_callback/2]).
|
||||||
|
|
||||||
-export_type([ pool_name/0
|
-export_type([ pool_name/0
|
||||||
, pool_type/0
|
, pool_type/0
|
||||||
|
@ -84,6 +84,12 @@ set_reconnect_callback(Pool, Callback) ->
|
||||||
|| {_WorkerName, Worker} <- ecpool:workers(Pool)],
|
|| {_WorkerName, Worker} <- ecpool:workers(Pool)],
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
-spec(add_reconnect_callback(atom(), reconn_callback()) -> ok).
|
||||||
|
add_reconnect_callback(Pool, Callback) ->
|
||||||
|
[ecpool_worker:add_reconnect_callback(Worker, Callback)
|
||||||
|
|| {_WorkerName, Worker} <- ecpool:workers(Pool)],
|
||||||
|
ok.
|
||||||
|
|
||||||
%% @doc Call the fun with client/connection
|
%% @doc Call the fun with client/connection
|
||||||
-spec(with_client(atom(), fun((Client :: pid()) -> any())) -> no_return()).
|
-spec(with_client(atom(), fun((Client :: pid()) -> any())) -> no_return()).
|
||||||
with_client(Pool, Fun) when is_atom(Pool) ->
|
with_client(Pool, Fun) when is_atom(Pool) ->
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
-export([ client/1
|
-export([ client/1
|
||||||
, is_connected/1
|
, is_connected/1
|
||||||
, set_reconnect_callback/2
|
, set_reconnect_callback/2
|
||||||
|
, add_reconnect_callback/2
|
||||||
]).
|
]).
|
||||||
|
|
||||||
%% gen_server Function Exports
|
%% gen_server Function Exports
|
||||||
|
@ -90,6 +91,10 @@ is_connected(Pid) ->
|
||||||
set_reconnect_callback(Pid, OnReconnect) ->
|
set_reconnect_callback(Pid, OnReconnect) ->
|
||||||
gen_server:cast(Pid, {set_reconn_callbk, OnReconnect}).
|
gen_server:cast(Pid, {set_reconn_callbk, OnReconnect}).
|
||||||
|
|
||||||
|
-spec(add_reconnect_callback(pid(), ecpool:reconn_callback()) -> ok).
|
||||||
|
add_reconnect_callback(Pid, OnReconnect) ->
|
||||||
|
gen_server:cast(Pid, {add_reconn_callbk, OnReconnect}).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
@ -130,6 +135,9 @@ handle_call(Req, _From, State) ->
|
||||||
handle_cast({set_reconn_callbk, OnReconnect}, State) ->
|
handle_cast({set_reconn_callbk, OnReconnect}, State) ->
|
||||||
{noreply, State#state{on_reconnect = OnReconnect}};
|
{noreply, State#state{on_reconnect = OnReconnect}};
|
||||||
|
|
||||||
|
handle_cast({add_reconn_callbk, OnReconnect}, State = #state{on_reconnect = OnReconnectList}) ->
|
||||||
|
{noreply, State#state{on_reconnect = [OnReconnect | OnReconnectList]}};
|
||||||
|
|
||||||
handle_cast(_Msg, State) ->
|
handle_cast(_Msg, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
|
@ -195,6 +203,10 @@ reconnect(Secs, State = #state{client = Client, on_disconnect = Disconnect, supe
|
||||||
|
|
||||||
handle_reconnect(_, undefined) ->
|
handle_reconnect(_, undefined) ->
|
||||||
ok;
|
ok;
|
||||||
|
handle_reconnect(undefined, _) ->
|
||||||
|
ok;
|
||||||
|
handle_reconnect(Client, OnReconnectList) when is_list(OnReconnectList) ->
|
||||||
|
[OnReconnect(Client) || OnReconnect <- OnReconnectList];
|
||||||
handle_reconnect(Client, OnReconnect) ->
|
handle_reconnect(Client, OnReconnect) ->
|
||||||
OnReconnect(Client).
|
OnReconnect(Client).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue