Listen to self send message for update

This commit is contained in:
Sergey Yelin 2021-07-20 12:11:08 +03:00
parent 27424a2c45
commit b9af9a70e8
No known key found for this signature in database
GPG Key ID: 0B653F3417EAEC54
2 changed files with 4 additions and 4 deletions

View File

@ -75,7 +75,7 @@ handle_cast(_Msg, State) ->
-spec handle_info(term(), state()) -> {noreply, state(), hibernate}.
handle_info(timeout, State0) ->
handle_info({timeout, TRef, update}, State0 = #state{timer = TRef}) ->
%% TODO add some sort of monitoring
%% to prevent metrics overloading entire system
#state{handler = Handler, handler_state = HandlerState} = State = restart_timer(State0),
@ -121,4 +121,4 @@ restart_timer(State = #state{timer = TimerRef}) ->
start_timer(State = #state{timer = undefined, handler = Handler, handler_state = HandlerState}) ->
Interval = Handler:get_interval(HandlerState),
State#state{timer = erlang:send_after(Interval, self(), timeout)}.
State#state{timer = erlang:start_timer(Interval, self(), update)}.

View File

@ -81,7 +81,7 @@ handle_cast(_Msg, State) ->
-spec handle_info(term(), state()) -> {noreply, state(), hibernate}.
handle_info(timeout, State0) ->
handle_info({timeout, TRef, publish}, State0 = #state{timer = TRef}) ->
%% TODO add some sort of monitoring
%% to prevent metrics overloading entire system
#state{handler = Handler, handler_state = HandlerState} = State = restart_timer(State0),
@ -110,4 +110,4 @@ restart_timer(State = #state{timer = TimerRef}) ->
start_timer(State = #state{timer = undefined, handler = Handler, handler_state = HandlerState}) ->
Interval = Handler:get_interval(HandlerState),
State#state{timer = erlang:send_after(Interval, self(), timeout)}.
State#state{timer = erlang:start_timer(Interval, self(), publish)}.