This commit is contained in:
Feng 2015-10-13 21:03:25 +08:00
parent 43523f2a1c
commit 5daeac083c
1 changed files with 5 additions and 0 deletions

View File

@ -34,10 +34,13 @@
tsec, tmsg, tref, tsec, tmsg, tref,
repeat = 0}). repeat = 0}).
-type keepalive() :: #keepalive{}.
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
%% @doc Start a keepalive %% @doc Start a keepalive
%% @end %% @end
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
-spec start(fun(), integer(), any()) -> undefined | keepalive().
start(_, 0, _) -> start(_, 0, _) ->
undefined; undefined;
start(StatFun, TimeoutSec, TimeoutMsg) -> start(StatFun, TimeoutSec, TimeoutMsg) ->
@ -50,6 +53,7 @@ start(StatFun, TimeoutSec, TimeoutMsg) ->
%% @doc Check keepalive, called when timeout. %% @doc Check keepalive, called when timeout.
%% @end %% @end
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
-spec check(keepalive()) -> {ok, keepalive()} | {error, any()}.
check(KeepAlive = #keepalive{statfun = StatFun, statval = LastVal, repeat = Repeat}) -> check(KeepAlive = #keepalive{statfun = StatFun, statval = LastVal, repeat = Repeat}) ->
case StatFun() of case StatFun() of
{ok, NewVal} -> {ok, NewVal} ->
@ -71,6 +75,7 @@ resume(KeepAlive = #keepalive{tsec = TimeoutSec, tmsg = TimeoutMsg}) ->
%% @doc Cancel Keepalive %% @doc Cancel Keepalive
%% @end %% @end
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
-spec cancel(keepalive()) -> ok.
cancel(#keepalive{tref = TRef}) -> cancel(#keepalive{tref = TRef}) ->
cancel(TRef); cancel(TRef);
cancel(undefined) -> cancel(undefined) ->