refactor(buffer_worker): avoid starting 0-time timers

This commit is contained in:
Thales Macedo Garitezi 2023-03-01 13:39:59 -03:00
parent e9ffabf936
commit 167b7a212f
1 changed files with 6 additions and 0 deletions

View File

@ -1540,6 +1540,12 @@ clear_disk_queue_dir(Id, Index) ->
ensure_flush_timer(Data = #{batch_time := T}) ->
ensure_flush_timer(Data, T).
ensure_flush_timer(Data = #{tref := undefined}, 0) ->
%% if the batch_time is 0, we don't need to start a timer, which
%% can be costly at high rates.
Ref = make_ref(),
self() ! {flush, {Ref, Ref}},
Data#{tref => {Ref, Ref}};
ensure_flush_timer(Data = #{tref := undefined}, T) ->
Ref = make_ref(),
TRef = erlang:send_after(T, self(), {flush, Ref}),